Choosing your Guarantees
https://doc.rust-lang.org/book/choosing-your-guarantees.html
Guaranteesは保証という意味の単語らしい。
use std::cell::Cell; use std::cell::RefCell; fn main() { let x = Cell::new(1); let y = &x; let z = &x; x.set(2); y.set(3); z.set(4); println!("{}", x.get()); let x = RefCell::new(vec![1,2,3,4]); { println!("{:?}", *x.borrow()) } { let mut my_ref = x.borrow_mut(); my_ref.push(1); } }
$ cargo run Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs Running `target/debug/5_8_choosing_your_guarantees` 4 [1, 2, 3, 4]