|
36 | 36 | //! would otherwise be disallowed though, there are occasions when interior mutability might be |
37 | 37 | //! appropriate, or even *must* be used, e.g. |
38 | 38 | //! |
39 | | -//! * Introducing inherited mutability roots to shared types. |
| 39 | +//! * Introducing mutability 'inside' of something immutable |
40 | 40 | //! * Implementation details of logically-immutable methods. |
41 | 41 | //! * Mutating implementations of `Clone`. |
42 | 42 | //! |
43 | | -//! ## Introducing inherited mutability roots to shared types |
| 43 | +//! ## Introducing mutability 'inside' of something immutable |
44 | 44 | //! |
45 | | -//! Shared smart pointer types, including `Rc<T>` and `Arc<T>`, provide containers that can be |
| 45 | +//! Many shared smart pointer types, including `Rc<T>` and `Arc<T>`, provide containers that can be |
46 | 46 | //! cloned and shared between multiple parties. Because the contained values may be |
47 | | -//! multiply-aliased, they can only be borrowed as shared references, not mutable references. |
48 | | -//! Without cells it would be impossible to mutate data inside of shared boxes at all! |
| 47 | +//! multiply-aliased, they can only be borrowed with `&`, not `&mut`. Without cells it would be |
| 48 | +//! impossible to mutate data inside of these smart pointers at all. |
49 | 49 | //! |
50 | 50 | //! It's very common then to put a `RefCell<T>` inside shared pointer types to reintroduce |
51 | 51 | //! mutability: |
|
65 | 65 | //! ``` |
66 | 66 | //! |
67 | 67 | //! Note that this example uses `Rc<T>` and not `Arc<T>`. `RefCell<T>`s are for single-threaded |
68 | | -//! scenarios. Consider using `Mutex<T>` if you need shared mutability in a multi-threaded |
69 | | -//! situation. |
| 68 | +//! scenarios. Consider using `RwLock<T>` or `Mutex<T>` if you need shared mutability in a |
| 69 | +//! multi-threaded situation. |
70 | 70 | //! |
71 | 71 | //! ## Implementation details of logically-immutable methods |
72 | 72 | //! |
|
0 commit comments