mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-21 17:52:12 +03:00
Rollup merge of #55377 - goffrie:patch-2, r=joshtriplett
Slight copy-editing for `std::cell::Cell` docs Hopefully this is a bit more precise and also more correct English.
This commit is contained in:
+5
-4
@@ -207,8 +207,8 @@
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Here you can see how using `Cell<T>` allows to use mutable field inside
|
||||
/// immutable struct (which is also called 'interior mutability').
|
||||
/// In this example, you can see that `Cell<T>` enables mutation inside an
|
||||
/// immutable struct. In other words, it enables "interior mutability".
|
||||
///
|
||||
/// ```
|
||||
/// use std::cell::Cell;
|
||||
@@ -225,10 +225,11 @@
|
||||
///
|
||||
/// let new_value = 100;
|
||||
///
|
||||
/// // ERROR, because my_struct is immutable
|
||||
/// // ERROR: `my_struct` is immutable
|
||||
/// // my_struct.regular_field = new_value;
|
||||
///
|
||||
/// // WORKS, although `my_struct` is immutable, field `special_field` is mutable because it is Cell
|
||||
/// // WORKS: although `my_struct` is immutable, `special_field` is a `Cell`,
|
||||
/// // which can always be mutated
|
||||
/// my_struct.special_field.set(new_value);
|
||||
/// assert_eq!(my_struct.special_field.get(), new_value);
|
||||
/// ```
|
||||
|
||||
Reference in New Issue
Block a user