I like Rust
Speed, Safety and Concurrency
Zero-cost abstractions
A simple trait
trait Foo {
fn bar(&self);
}
Static dispatch
fn call_bar<T: Foo>(t: T) {
t.bar()
}
A unit-like struct
struct Foo { }
Zero sized!
assert!(size_of::<Foo>() == 0)
Stateless trait implementations
impl Bar for Foo {
fn bar(&self) {
// magic here
}
}
A tuple struct with one element!
struct FooBar(usize);
No memory overhead!
assert!(size_of::<FooBar>() == size_of::<usize>())
Validated types
impl Vector {
pub fn normalize(self) -> UnitVector {
UnitVector::from(self)
}
}
Stateless decorators
struct LogFoo<T: Foo>(T);
impl<T: Foo> Foo for LogFoo<T> {
fn bar(&self) -> Bar {
let bar = self.0.bar();
println!("result of foo: {:?}", bar);
return bar;
}
}
std::cell::Ref
pub struct Ref<'b, T> where T: 'b + ?Sized {
// some fields omitted
}
Projections
struct Polygon(Vec<Point>);
struct PolygonEdge<'a>(&'a Point, &'a Point);
struct SubPolygon<'a>(Vec<&'a Point>);
This slide is intentionally left blank
Useful links
Summary
Any questions?