Antoine Wacheux
awacheux.utc@gmail.comC++ is heavily used in the industry. It is efficient and portable.
Recent improvement : lambdas, closure, type inference.
fn main() { println!("Hello l'UTC"); }
Hello l'UTCPut your speaker notes here. You can see them pressing 's'.
use std::num::Float; struct Point { x:f64, y:f64 } fn main() { let a = Point { x:3.0, y:4.0 }; let dist = (a.x*a.x + a.y*a.y).sqrt(); println!("{} {} {}", a.x, a.y, dist); }
3 4 5Equivalent aux classes. Pas de classes abstraites.
use std::f64::consts::PI; use std::num::Float; struct Circle { x:f64, y:f64, radius:f64 } impl Circle { fn area(&self) -> f64 { PI*self.radius*self.radius } } fn main() { let c = Circle { x:3.0, y:3.0, radius:2.0 }; println!("{:?}", c.area()); }
12.566371Implémentation dans des blocs modulaires. Méthodes statiques.
trait HasArea { fn area(&self) -> f64; } struct Circle { x:f64, y:f64, radius:f64 } impl HasArea for Circle { fn area(&self) -> f64 { PI*self.radius*self.radius } } struct Rect { x1:f64, y1:f64, x2:f64, y2:f64 } impl HasArea for Rect { fn area(&self) -> f64 { (self.x2-self.x1).abs()*(self.y2-self.y1).abs() } } fn main() { let r = Rect { x1:3.0, y1:3.0, x2:10.0, y2: 7.0}; let c = Circle { x:3.0, y:3.0, radius:2.0 }; println!("{:?} {:?}", r.area(), c.area()); }
28 12.566371Equivalent classes abstraites pures. Permet le polymorphisme et le dispatching dynamique
enum Resultat { Erreur(String), Ok(i32) } fn diviser(a: i32, b: i32) -> Resultat { if b == 0 { Erreur(String::from("Division par 0")) } else { Ok(a/b) } } fn main() { match diviser(4, 2) { Erreur(msg) => println!("{}", msg), Ok(result) => println!("Resultat : {}", result), } }
Resultat : 2Type pouvant prendre un ensemble de valeur + payload. Exemple Option / Result
Lot of topics to cover !
Official website : https://www.rust-lang.org/
Lot of examples : http://rustbyexample.com/
#LO21 : https://github.com/Shiroy/NPI
Put your speaker notes here. You can see them pressing 's'.