mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-06-10 09:19:23 +00:00
27 lines
504 B
Rust
27 lines
504 B
Rust
|
// ./src/scope/move/mut.md
|
||
|
|
||
|
|
||
|
fn part0() {
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
pub fn main() {
|
||
|
part0();
|
||
|
}
|
||
|
|