diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 1610e89a82d..1e7c8dfce5b 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -187,9 +187,12 @@ use ops::{Deref, DerefMut, CoerceUnsized}; use ptr; /// A mutable memory location. +/// /// # Examples +/// /// Here you can see how using `Cell` allows to use mutable field inside /// immutable struct (which is also called 'interior mutability'). +/// /// ``` /// use std::cell::Cell; /// @@ -204,8 +207,10 @@ use ptr; /// }; /// /// let new_value = 100; +/// /// // ERROR, because my_struct is immutable /// // immutable.regular_field = new_value; +/// /// // WORKS, although `my_struct` is immutable, field `special_field` is mutable because it is Cell /// immutable.special_field.set(new_value); /// assert_eq!(immutable.special_field.get(), new_value);