Mutability - Rust By Example
Description: Rust by Example (RBE) is a collection of runnable examples that illustrate various Rust concepts and standard libraries.

## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# Mutability

Mutability of data can be changed when ownership is transferred.

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

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

        // Mutability error
        //*immutable_box = 4;

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

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

        // Modify the contents of the box
        *mutable_box = 4;

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