Mutability

Mutability of data can be changed when ownership is transferred.

1. fn main() {
2. let immutable_box = Box::new(5u32);

4. println!("immutable_box contains {}", immutable_box);

6. // Mutability error
7. //*immutable_box = 4;

9. // *Move* the box, changing the ownership (and mutability)
10. let mut mutable_box = immutable_box;

12. println!("mutable_box contains {}", mutable_box);

14. // Modify the contents of the box
15. *mutable_box = 4;

17. println!("mutable_box now contains {}", mutable_box);
18. }