a gets deallocated. fn main() { let a = vec!(1, 2, 3, 4); let sum_of_a = sum( a); // a is no longer accessible here. // ... } https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=192e9a1c3c68c4f0727c940af1922ba0
-> Self { YourFace { hat: self.hat, } } } | 14 | hat: self.hat, | ^^^^^^^^ move occurs because `self.hat` has type `T`, which does not implement the `Copy` trait
fn do_something(person: Name) { | ^^^^ help: use `dyn`: `dyn Name` | = note: `#[warn(bare_trait_objects)]` on by default error[E0277]: the size for values of type `(dyn Name + 'static)` cannot be known at compilation time trait Name { fn name(&self) -> String; }
Small footprint (no scheduling). - Compiles to a state machine. - Small footprint (allocates memory only once). - Lazy (sort of). pub trait Future { type Output; fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output>; } Implicit contract: once polled, will notify executor when value is ready.
another_function() { // Create the future: let future = first_function(); // Await the future, which will execute it (and suspend // this function if we encounter a need to wait for I/O): let result: u32 = future .await; ... }