Rc<T>, Box<T>, RefCell<T>, Cell<T>
- Rc
enables multiple owners of the same data; Box and RefCell have single owners. - Box
allows immutable or mutable borrows checked at compile time; Rc allows only immutable borrows checked at compile time; RefCell allows immutable or mutable borrows checked at runtime. - Because RefCell
allows mutable borrows checked at runtime, you can mutate the value inside the RefCell even when the RefCell is immutable.
The standard library has other types that provide interior mutability, such as Cell
+V why_null 请备注:from博客园