Skip to content

Commit daa5091

Browse files
committed
Update cell docs
1 parent afac3ec commit daa5091

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/libcore/cell.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@
1515
//! references. We say that `Cell<T>` and `RefCell<T>` provide 'interior mutability', in contrast
1616
//! with typical Rust types that exhibit 'inherited mutability'.
1717
//!
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.
2230
//!
2331
//! `RefCell<T>` uses Rust's lifetimes to implement 'dynamic borrowing', a process whereby one can
2432
//! claim temporary, exclusive, mutable access to the inner value. Borrows for `RefCell<T>`s are
@@ -179,7 +187,7 @@ use marker::Unsize;
179187
use mem;
180188
use ops::{Deref, DerefMut, CoerceUnsized};
181189

182-
/// A mutable memory location that admits only `Copy` data.
190+
/// A mutable memory location.
183191
///
184192
/// See the [module-level documentation](index.html) for more.
185193
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)