可变性 - 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

# 可变性

当所有权转移时，数据的可变性可以改变。

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

        println!("immutable_box 包含 {}", immutable_box);

        // 可变性错误
        //*immutable_box = 4;

        // *移动*盒子，改变所有权（和可变性）
        let mut mutable_box = immutable_box;

        println!("mutable_box 包含 {}", mutable_box);

        // 修改盒子的内容
        *mutable_box = 4;

        println!("mutable_box 现在包含 {}", mutable_box);
    }