From 238bb38a948ddf3d782f8138b39868cb08356c91 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 22 Feb 2018 13:53:59 -0500 Subject: [PATCH 1/8] First version --- src/libcore/cell.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index ec0d1b704dceb..75ed562ae5401 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` and `RefCell` allows to do this in a single threaded +//! way. For multiple threads is possible to use `Mutex`, `RwLock` or `AtomicXXX`. +//! //! Values of the `Cell` and `RefCell` 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` and `RefCell` 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` and `RefCell`. `Cell` implements interior //! mutability by moving values in and out of the `Cell`. To use references instead of values, From f9e049afc544e70dc595df67d878b52c098aaa9a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Feb 2018 12:57:18 -0500 Subject: [PATCH 2/8] add info about sync --- src/libcore/cell.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 75ed562ae5401..1067b6ff0c11e 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -22,7 +22,9 @@ //! //! Shareable mutable containers exist to permit mutability in presence of aliasing in a //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded -//! way. For multiple threads is possible to use `Mutex`, `RwLock` or `AtomicXXX`. +//! way, you can mutate them using an inmutable reference. However, neither `Cell` nor +//! `RefCell` are thread safe (they do not implement `Sync`), if you need to do Aliasing and +//! Mutation between multiple threads is possible to use `Mutex`, `RwLock` or `AtomicXXX`. //! //! Values of the `Cell` and `RefCell` 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`) From 58d1f839520b97ac06e48aeb49d814282b20056c Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Feb 2018 13:00:26 -0500 Subject: [PATCH 3/8] remove redundant info --- src/libcore/cell.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 1067b6ff0c11e..b3a7d20c4aa5f 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -17,19 +17,19 @@ //! - 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 +//! 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` and `RefCell` allows to do this in a single threaded -//! way, you can mutate them using an inmutable reference. However, neither `Cell` nor -//! `RefCell` are thread safe (they do not implement `Sync`), if you need to do Aliasing and -//! Mutation between multiple threads is possible to use `Mutex`, `RwLock` or `AtomicXXX`. +//! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement +//! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use +//! `Mutex`, `RwLock` or `AtomicXXX`. //! //! Values of the `Cell` and `RefCell` 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` and `RefCell` 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` and `RefCell`. `Cell` implements interior //! mutability by moving values in and out of the `Cell`. To use references instead of values, From 43de01f97eeee13f9bf9f19b0b241e8368633d11 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Feb 2018 15:12:28 -0500 Subject: [PATCH 4/8] cleaned trailing whitespaces --- src/libcore/cell.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index b3a7d20c4aa5f..6f0655f2033e1 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -20,9 +20,9 @@ //! 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 +//! Shareable mutable containers exist to permit mutability in presence of aliasing in a //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded -//! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement +//! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement //! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use //! `Mutex`, `RwLock` or `AtomicXXX`. //! From ce3ad263ff085ac15016430de5f4abb154427433 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 24 Feb 2018 18:04:08 -0500 Subject: [PATCH 5/8] added link to sync containers --- src/libcore/cell.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 6f0655f2033e1..91074c18d771a 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -24,7 +24,8 @@ //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded //! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement //! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use -//! `Mutex`, `RwLock` or `AtomicXXX`. +//! [`Mutex`](../sync/struct.Mutex.html), [`RwLock`](../sync/struct.RwLock.html) or +//! [`atomic`](../sync/atomic/index.html) types. //! //! Values of the `Cell` and `RefCell` 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`) From 7ded7f764c2d590d0c3ad71b9ffbbcfaec2174fb Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 24 Feb 2018 18:06:01 -0500 Subject: [PATCH 6/8] corrected grammar errors --- src/libcore/cell.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 91074c18d771a..858bdcbb72110 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -10,17 +10,17 @@ //! Shareable mutable containers. //! -//! Rust memory safety is based on this rule: Given an object `T`, is only possible to +//! Rust memory safety is based on this rule: Given an object `T`, it is only possible to //! have one of the following: //! -//! - Having several inmutable references (`&T`) to the object (also know as Aliasing). +//! - Having several immutable 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 +//! flexible enough. Sometimes it 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 +//! Shareable mutable containers exist to permit mutability in the presence of aliasing in a //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded //! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement //! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use From 397ce8a1aedd0734cbf9b7dfb36ea18fbe6a5d91 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 24 Feb 2018 22:43:30 -0500 Subject: [PATCH 7/8] fixed links --- src/libcore/cell.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 858bdcbb72110..a946aca68d1b2 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -24,8 +24,8 @@ //! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded //! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement //! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use -//! [`Mutex`](../sync/struct.Mutex.html), [`RwLock`](../sync/struct.RwLock.html) or -//! [`atomic`](../sync/atomic/index.html) types. +//! [`Mutex`](../../std/sync/struct.Mutex.html), [`RwLock`](../../std/sync/struct.RwLock.html) or +//! [`atomic`](../../core/sync/atomic/index.html) types. //! //! Values of the `Cell` and `RefCell` 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`) From 9091584def3b566f24f8fbeac495e6dc87178be8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 26 Feb 2018 11:14:40 -0500 Subject: [PATCH 8/8] some grammar corrections --- src/libcore/cell.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index a946aca68d1b2..37f301c590928 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -13,18 +13,19 @@ //! Rust memory safety is based on this rule: Given an object `T`, it is only possible to //! have one of the following: //! -//! - Having several immutable references (`&T`) to the object (also know as Aliasing). -//! - Having one mutable reference (`&mut T`) to the object (also know as Mutability). +//! - Having several immutable references (`&T`) to the object (also known as **aliasing**). +//! - Having one mutable reference (`&mut T`) to the object (also known as **mutability**). //! //! This is enforced by the Rust compiler. However, there are situations where this rule is not //! flexible enough. Sometimes it is required to have multiple references to an object and yet //! mutate it. //! -//! Shareable mutable containers exist to permit mutability in the presence of aliasing in a -//! controlled manner. Both `Cell` and `RefCell` allows to do this in a single threaded +//! Shareable mutable containers exist to permit mutability in a controlled manner, even in the +//! presence of aliasing. Both `Cell` and `RefCell` allows to do this in a single threaded //! way. However, neither `Cell` nor `RefCell` are thread safe (they do not implement -//! `Sync`), if you need to do Aliasing and Mutation between multiple threads is possible to use -//! [`Mutex`](../../std/sync/struct.Mutex.html), [`RwLock`](../../std/sync/struct.RwLock.html) or +//! `Sync`). If you need to do aliasing and mutation between multiple threads it is possible to +//! use [`Mutex`](../../std/sync/struct.Mutex.html), +//! [`RwLock`](../../std/sync/struct.RwLock.html) or //! [`atomic`](../../core/sync/atomic/index.html) types. //! //! Values of the `Cell` and `RefCell` types may be mutated through shared references (i.e.