I’m not actually a Rust developer!
There is a lot to cover.
If you get bored or overwhelmed, just yet at me!
The order of the slides may be confusing; its just hard to prioritize and there is just so much I would like to talk about.
borrowck
// Hello Rust!
fn main() {
println!("Hello Rust!");
}
struct Foo {
foo: (u8, u8),
bar: u16,
}
pub enum Option<T> {
None,
Some(T),
}
impl<T> Option<T> {
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> {
match self {
Some(x) => Some(f(x)),
None => None,
}
}
}
pub trait Read {
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> { ... }
fn read_to_string(&mut self, buf: &mut String) -> Result<usize> { ... }
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()> { ... }
fn by_ref(&mut self) -> &mut Self where Self: Sized { ... }
fn bytes(self) -> Bytes<Self> where Self: Sized { ... }
fn chars(self) -> Chars<Self> where Self: Sized { ... }
fn chain<R: Read>(self, next: R) -> Chain<Self, R> where Self: Sized { ... }
fn take(self, limit: u64) -> Take<Self> where Self: Sized { ... }
fn tee<W: Write>(self, out: W) -> Tee<Self, W> where Self: Sized { ... }
}
impl Read for Foo {
fn read(&mut self, but: &mut [u8]) -> Result<usize> {
// …
}
}
trait Foo {
fn foo(&self) -> u32 {
1
}
}
struct Bar<T> {
bar: T,
}
impl Foo for u32 {}
impl<'a> Foo for &'a str {}
impl<T> Foo for Bar<T> {}
fn foo<T>(arg: T) -> u32 where T: Foo {
arg.foo()
}
fn main() {
println!("{}", foo(10));
println!("{}", foo("foo"));
println!("{}", foo(Bar{bar: Bar{bar: "bar"}}));
}
use std::ops::Add;
#[derive(Copy, Clone)]
struct Foo;
impl Add for Foo {
type Output = Foo;
fn add(self, _rhs: Foo) -> Foo {
println!("Adding!");
self
}
}
fn main() {
Foo + Foo;
}
impl Send for Arc<T>
impl !Send for Rc<T>
impl Sync for Mutex<T>
fn<T: Bar> foo(bar: &T) {
// …
}
// vs
fn foo(bar: &Bar) {
// …
}