|
15 | 15 | //! references. We say that `Cell<T>` and `RefCell<T>` provide 'interior mutability', in contrast
|
16 | 16 | //! with typical Rust types that exhibit 'inherited mutability'.
|
17 | 17 | //!
|
18 |
| -//! Cell types come in two flavors: `Cell<T>` and `RefCell<T>`. `Cell<T>` provides `get` and `set` |
19 |
| -//! methods that change the interior value with a single method call. `Cell<T>` though is only |
20 |
| -//! compatible with types that implement `Copy`. For other types, one must use the `RefCell<T>` |
21 |
| -//! type, acquiring a write lock before mutating. |
| 18 | +//! Cell types come in two flavors: `Cell<T>` and `RefCell<T>`. `Cell<T>` implements interior |
| 19 | +//! mutability by moving values in and out of the `Cell<T>`. To use references instead of values, |
| 20 | +//! one must use the `RefCell<T>` type, acquiring a write lock before mutating. `Cell<T>` provides |
| 21 | +//! methods to retrieve and change the current interior value: |
| 22 | +//! |
| 23 | +//! - For types that implement `Copy`, the `get` method retrieves the current interior value. |
| 24 | +//! - For types that implement `Default`, the `take` method replaces the current interior value |
| 25 | +//! with `Default::default()` and returns the replaced value. |
| 26 | +//! - For all types, the `replace` method replaces the current interior value and returns the |
| 27 | +//! replaced value and the `into_inner` method consumes the `Cell<T>` and returns the interior |
| 28 | +//! value. Additionally, the `set` method replaces the interior value, dropping the replaced |
| 29 | +//! value. |
22 | 30 | //!
|
23 | 31 | //! `RefCell<T>` uses Rust's lifetimes to implement 'dynamic borrowing', a process whereby one can
|
24 | 32 | //! claim temporary, exclusive, mutable access to the inner value. Borrows for `RefCell<T>`s are
|
@@ -179,7 +187,7 @@ use marker::Unsize;
|
179 | 187 | use mem;
|
180 | 188 | use ops::{Deref, DerefMut, CoerceUnsized};
|
181 | 189 |
|
182 |
| -/// A mutable memory location that admits only `Copy` data. |
| 190 | +/// A mutable memory location. |
183 | 191 | ///
|
184 | 192 | /// See the [module-level documentation](index.html) for more.
|
185 | 193 | #[stable(feature = "rust1", since = "1.0.0")]
|
|
0 commit comments