diff options
| author | Federico Mena Quintero <federico@gnome.org> | 2017-01-25 13:11:15 -0600 |
|---|---|---|
| committer | Federico Mena Quintero <federico@gnome.org> | 2017-01-31 18:02:41 -0600 |
| commit | 4a07e722c01962aa814f2ae0915dfa84cd4d732a (patch) | |
| tree | 4b38e3830ba6f628a4fb4e7eeddfbfe4dbde773a /src/liballoc | |
| parent | 1283c029557bcde106adde71f467fe133b3ffeff (diff) | |
| download | rust-4a07e722c01962aa814f2ae0915dfa84cd4d732a.tar.gz rust-4a07e722c01962aa814f2ae0915dfa84cd4d732a.zip | |
In std:rc, clarify the lack of mutability inside an Rc
Also, point to the example in Cell's docs for how to do it.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/rc.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 010e378ef2f..6108a06634b 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -17,9 +17,11 @@ //! pointer to the same value in the heap. When the last [`Rc`] pointer to a //! given value is destroyed, the pointed-to value is also destroyed. //! -//! Shared references in Rust disallow mutation by default, and `Rc` is no -//! exception. If you need to mutate through an [`Rc`], use [`Cell`] or -//! [`RefCell`]. +//! Shared references in Rust disallow mutation by default, and [`Rc`] +//! is no exception: you cannot obtain a mutable reference to +//! something inside an [`Rc`]. If you need mutability, put a [`Cell`] +//! or [`RefCell`] inside the [`Rc`]; see [an example of mutability +//! inside an Rc][mutability]. //! //! [`Rc`] uses non-atomic reference counting. This means that overhead is very //! low, but an [`Rc`] cannot be sent between threads, and consequently [`Rc`] @@ -214,6 +216,7 @@ //! [upgrade]: struct.Weak.html#method.upgrade //! [`None`]: ../../std/option/enum.Option.html#variant.None //! [assoc]: ../../book/method-syntax.html#associated-functions +//! [mutability]: ../../std/cell/index.html#introducing-mutability-inside-of-something-immutable #![stable(feature = "rust1", since = "1.0.0")] |
