Ownership
All variable bindings have a scope where they are valid and it is an error to use a variable outside its scope:
1. struct Point(i32, i32);
3. fn main() {
4. {
5. let p = Point(3, 4);
6. println!("x: {}", p.0);
7. }
8. println!("y: {}", p.1);
9. }
- At the end of the scope, the variable is dropped and the data is freed.
- A destructor can run here to free up resources.
- We say that the variable owns the value.
