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 = 4;

    // 상자를 *이동*하여 소유권(및 가변성)을 변경합니다
    let mut mutable_box = immutable_box;

    println!("가변 상자가 포함하는 것: {}", mutable_box);

    // 상자의 내용물을 수정합니다
    *mutable_box = 4;

    println!("가변 상자가 이제 포함하는 것: {}", mutable_box);
}