Mozilla employee Graydon Hoare Mozilla began sponsoring the project in 2009 and announced it in 2010 A young language, with a growing usage in production (Dropbox, Mozilla, Canonical, OVH, ...) 2 . 1
[unoptimized + debuginfo] target(s) in 0.0 secs Doc-tests hello-world-lib running 1 test test greater_0 ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured 9
-> String { format!("Hello, {}!", name) } Where is the `return`? It's implicit, the last expression is returned ... beware of forgetting some `return` in Python after a switch :) 10
Restituisce un saluto di default se il nome è None //! //! ``` //! use hello_world_lib::greater2; //! let message = greater2(None); //! assert_eq!(message, "Hello, World!"); //! //! let message = greater2(Some("Matteo")); //! assert_eq!(message, "Hello, Matteo!"); //! ``` let name = match optional_name { Some(name) => name, None => "World", }; format!("Hello, {}!", name) } no default values... yet `if` and `match`are expressions in Rust 11
res = do_something_with(var) else: res = None res = if let Some(var) = some_optional_value() { Some(do_something_with(var)) } else { None } Python Rust 12
} trait HasArea { fn area(&self) -> f64; } impl HasArea for Circle { fn area(&self) -> f64 { std::f64::consts::PI * (self.radius * self.radius) } } this is what your lib users will need to implement 18
of {}".format(shape.area())); } Traits are something we can use where in Python we were using duck typing fn print_area<T: HasArea>(shape: T) { println!("This shape has an area of {}", shape.area()); } Python Rust 19
f(x,y) = | | · | | + | | \ c d / \ y / \ f / Given 4 linear function with some magic parameters (a,b,c,d,e,f) Choose a random starting point, say (0,0) Loop: pick a random function apply the func on the last point collect the result Iterated Function System Barnsley fern 24
f == 0: P = F1 * P + F1c elif f == 1: P = F2 * P + F2c elif f == 2: P = F3 * P + F3c else: P = F4 * P + F4c if i > pointsToSkip: drawPoints[frame][i-pointsToSkip] = squeeze(asarray(P)) 25 . 2
= wc.ind_sample(&mut rng); if f == 1 { p = f1 * p + f1c; } else if f == 2 { p = f2 * p + f2c; } else if f == 3 { p = f3 * p + f3c; } else { p = f4 * p + f4c; } if i > points_to_skip { points.push((p.x, p.y)); } } 25 . 3