diff options
| author | Tymoteusz Jankowski <tymoteusz.jankowski@gmail.com> | 2017-07-23 14:18:34 +0200 |
|---|---|---|
| committer | Tymoteusz Jankowski <tymoteusz.jankowski@gmail.com> | 2017-07-23 14:28:29 +0200 |
| commit | 236b7487d525359440815a425cba97fa36903afc (patch) | |
| tree | 0a7b5d551195c234bbf4a0813e46893610b43bb2 | |
| parent | 35f64996ad5639173040097a0fe718e25d0dc29d (diff) | |
| download | rust-236b7487d525359440815a425cba97fa36903afc.tar.gz rust-236b7487d525359440815a425cba97fa36903afc.zip | |
Add simple docs example for struct Cell
| -rw-r--r-- | src/libcore/cell.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 35744f3f16b..7e12d5466c2 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -187,6 +187,29 @@ use ops::{Deref, DerefMut, CoerceUnsized}; use ptr; /// A mutable memory location. +/// +/// ``` +/// use std::cell::Cell; +/// +/// struct SomeStruct { +/// regular_field: u8, +/// special_field: Cell<u8>, +/// } +/// +/// let my_struct = SomeStruct { +/// regular_field: 0, +/// special_field: Cell::new(1), +/// }; +/// +/// let new_value = 100; +/// +/// // ERROR, because my_struct is immutable +/// // immutable.regular_field = new_value; +/// +/// // WORKS, special_field is mutable because it is Cell +/// immutable.special_field.set(new_value); +/// assert_eq!(immutable.special_field.get(), new_value); +/// ``` /// /// See the [module-level documentation](index.html) for more. #[stable(feature = "rust1", since = "1.0.0")] |
