Rust by Example

18.2 Freezing

When data is borrowed, it also freezes. Frozen data can't be modified via the original object, until all the references to it go out of scope.

fn main() { let mut _integer = 5i32; { // Borrow `integer` let _ref_to_integer = &_integer; // Error! `integer` is frozen in this scope _integer = 4; // FIXME ^ Comment out this line // `ref_to_integer` goes out of scope } // Ok! `integer` is not frozen in this scope _integer = 4; }