未验证 提交 ac9d5ec7 编写于 作者: K kennytm 提交者: GitHub

Rollup merge of #55377 - goffrie:patch-2, r=joshtriplett

Slight copy-editing for `std::cell::Cell` docs

Hopefully this is a bit more precise and also more correct English.
...@@ -207,8 +207,8 @@ ...@@ -207,8 +207,8 @@
/// ///
/// # Examples /// # Examples
/// ///
/// Here you can see how using `Cell<T>` allows to use mutable field inside /// In this example, you can see that `Cell<T>` enables mutation inside an
/// immutable struct (which is also called 'interior mutability'). /// immutable struct. In other words, it enables "interior mutability".
/// ///
/// ``` /// ```
/// use std::cell::Cell; /// use std::cell::Cell;
...@@ -225,10 +225,11 @@ ...@@ -225,10 +225,11 @@
/// ///
/// let new_value = 100; /// let new_value = 100;
/// ///
/// // ERROR, because my_struct is immutable /// // ERROR: `my_struct` is immutable
/// // my_struct.regular_field = new_value; /// // my_struct.regular_field = new_value;
/// ///
/// // WORKS, although `my_struct` is immutable, field `special_field` is mutable because it is Cell /// // WORKS: although `my_struct` is immutable, `special_field` is a `Cell`,
/// // which can always be mutated
/// my_struct.special_field.set(new_value); /// my_struct.special_field.set(new_value);
/// assert_eq!(my_struct.special_field.get(), new_value); /// assert_eq!(my_struct.special_field.get(), new_value);
/// ``` /// ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册