May 2019
Intermediate to advanced
698 pages
17h 21m
English
Apart from the let binding example, there are other places where you will find ownership in effect, and it's important to recognize these and the errors the compiler gives us.
Functions: If you pass parameters to functions, the same ownership rules are in effect:
// ownership_functions.rsfn take_the_n(n: u8) { }fn take_the_s(s: String) { }fn main() { let n = 5; let s = String::from("string"); take_the_n(n); take_the_s(s); println!("n is {}", n); println!("s is {}", s); }
The compilation fails in a similar way:

String does not implement the Copy trait, so the ownership of the value is moved inside the take_the_s
Read now
Unlock full access