summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poveda <christianpoveda@protonmail.com>2018-02-22 13:53:59 -0500
committerChristian Poveda <christianpoveda@protonmail.com>2018-02-22 13:53:59 -0500
commit238bb38a948ddf3d782f8138b39868cb08356c91 (patch)
tree3a177c4d8283dd783b9eb795d8ab4ad047a51e31
parent27a046e9338fb0455c33b13e8fe28da78212dedc (diff)
downloadrust-238bb38a948ddf3d782f8138b39868cb08356c91.tar.gz
First version
-rw-r--r--src/libcore/cell.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index ec0d1b704dc..75ed562ae54 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -10,10 +10,24 @@
//! Shareable mutable containers.
//!
+//! Rust memory safety is based on this rule: Given an object `T`, is only possible to
+//! have one of the following:
+//!
+//! - Having several inmutable references (`&T`) to the object (also know as Aliasing).
+//! - Having one mutable reference (`&mut T`) to the object (also know as Mutability).
+//!
+//! This is enforced by the Rust compiler. However, there are situations where this rule is not
+//! flexible enough. Sometimes is required to have multiple references to an object and yet
+//! mutate it.
+//!
+//! Shareable mutable containers exist to permit mutability in presence of aliasing in a
+//! controlled manner. Both `Cell<T>` and `RefCell<T>` allows to do this in a single threaded
+//! way. For multiple threads is possible to use `Mutex`, `RwLock` or `AtomicXXX`.
+//!
//! Values of the `Cell<T>` and `RefCell<T>` types may be mutated through shared references (i.e.
//! the common `&T` type), whereas most Rust types can only be mutated through unique (`&mut T`)
//! references. We say that `Cell<T>` and `RefCell<T>` provide 'interior mutability', in contrast
-//! with typical Rust types that exhibit 'inherited mutability'.
+//! with typical Rust types that exhibit 'inherited mutability'.
//!
//! Cell types come in two flavors: `Cell<T>` and `RefCell<T>`. `Cell<T>` implements interior
//! mutability by moving values in and out of the `Cell<T>`. To use references instead of values,