This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait A { | |
fn a(&self); | |
} | |
trait B { | |
fn b(&self); | |
} | |
trait C { | |
fn c(&self); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cell::Cell; | |
#[derive(Debug)] | |
struct Ab { | |
a: i32, | |
b: i32, | |
cache: Cell<Option<i32>> | |
} | |
impl Ab { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate rand; | |
use rand::Rng; | |
const WIDTH : usize = 80; | |
const HEIGH : usize = 40; | |
const SIZE : usize = WIDTH * HEIGH; | |
type MatrixLine = [bool; WIDTH]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops::Mul; | |
#[derive(Debug)] | |
struct Vector { | |
x : f64, | |
y : f64 | |
} | |
impl<'a> Mul<f64> for &'a Vector { | |
type Output = Vector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Point { | |
x : f64, | |
} | |
trait Math : { | |
fn sub(&self, &Self) -> Self; | |
fn add(&self, &Self) -> Self; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Point { | |
x : f64, | |
} | |
trait Add { | |
fn add(&self, &Self) -> Self; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait HasArea { | |
fn area(&self) -> f64; | |
} | |
struct Cyrcle { | |
radius : f64, | |
} | |
impl HasArea for Cyrcle { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let v1 = vec![4, 8, 12, 16]; | |
let v2 = mult(&v1, 10); | |
pv("v1", &v1); | |
pv("v2", &v2); | |
println!(""); | |
println!("{}", v1[2]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let funcs = [ | |
("+", sum as fn(f64, f64) -> f64), | |
("-", sub), | |
("*", mult), | |
("/", div), | |
("^", pow) | |
]; | |
for &(name, func) in funcs.iter() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Benchmark of djb2, sdbm and lose lose hashing algorithms | |
# Algorithm descriptions: http://www.cse.yorku.ca/~oz/hash.html | |
# Output | |
# | |
# ===== djb2 ===== | |
# Values: 5000000 | |
# Collisions: 2988 | |
# Time: 0.76589 | |
# |