Propagate chapter 15 tech review edits to src

This commit is contained in:
Carol (Nichols || Goulding) 2022-06-04 20:37:55 -04:00
parent 85a94d95c0
commit 5041156975
No known key found for this signature in database
GPG Key ID: E907EE5A736F87D4
4 changed files with 18 additions and 21 deletions

View File

@ -1580,7 +1580,7 @@ access to its interior mutability so we can modify our data when we need to.
The runtime checks of the borrowing rules protect us from data races, and its
sometimes worth trading a bit of speed for this flexibility in our data
structures. Note that `RefCell<T>` does not work for multithreaded code!
`Mutex<T>` is the threadsafe version of `RefCell<T>` and well discuss
`Mutex<T>` is the thread-safe version of `RefCell<T>` and well discuss
`Mutex<T>` in Chapter 16.
<!-- While we mention threading a little bit, I think we should take a little

View File

@ -76,10 +76,11 @@ more complex situations involving recursive types.
#### More Information About the Cons List
A *cons list* is a data structure that comes from the Lisp programming language
and its dialects and is made up of nested pairs. Its name comes from the `cons`
function (short for “construct function”) in Lisp that constructs a new pair
from its two arguments. By calling `cons` on a pair consisting of a value and
another pair, we can construct cons lists made up of recursive pairs.
and its dialects and is made up of nested pairs, and is the Lisp version of a
linked list. Its name comes from the `cons` function (short for “construct
function”) in Lisp that constructs a new pair from its two arguments. By
calling `cons` on a pair consisting of a value and another pair, we can
construct cons lists made up of recursive pairs.
For example, here's a pseudocode representation of a cons list containing the
list 1, 2, 3 with each pair in parentheses:

View File

@ -192,7 +192,7 @@ Listing 15-9.
*Deref coercion* converts a reference to a type that implements the `Deref`
trait into a reference to another type. For example, deref coercion can convert
`&String` to `&str` because `String` implements the `Deref` trait such that it
returns `&str`. Deref conversion is a convenience Rust performs on arguments to
returns `&str`. Deref coercion is a convenience Rust performs on arguments to
functions and methods, and works only on types that implement the `Deref`
trait. It happens automatically when we pass a reference to a particular types
value as an argument to a function or method that doesnt match the parameter

View File

@ -4,13 +4,14 @@
data even when there are immutable references to that data; normally, this
action is disallowed by the borrowing rules. To mutate data, the pattern uses
`unsafe` code inside a data structure to bend Rusts usual rules that govern
mutation and borrowing. We havent yet covered unsafe code that indicates we're
checking the rules manually instead of the compiler checking them for us; we
will discuss unsafe code more in Chapter 19. We can use types that use the
interior mutability pattern only when we can ensure that the borrowing rules
will be followed at runtime, even though the compiler cant guarantee that. The
`unsafe` code involved is then wrapped in a safe API, and the outer type is
still immutable.
mutation and borrowing. mutation and borrowing. Unsafe code indicates to the
compiler that were checking the rules manually instead of relying on the
compiler to check them for us; we will discuss unsafe code more in Chapter 19.
We can use types that use the interior mutability pattern only when we can
ensure that the borrowing rules will be followed at runtime, even though the
compiler cant guarantee that. The `unsafe` code involved is then wrapped in a
safe API, and the outer type is still immutable.
Lets explore this concept by looking at the `RefCell<T>` type that follows the
interior mutability pattern.
@ -336,13 +337,8 @@ immutable `List` value. But we can use the methods on `RefCell<T>` that provide
access to its interior mutability so we can modify our data when we need to.
The runtime checks of the borrowing rules protect us from data races, and its
sometimes worth trading a bit of speed for this flexibility in our data
structures.
The standard library has other types that provide interior mutability, such as
`Cell<T>`, which is similar except that instead of giving references to the
inner value, the value is copied in and out of the `Cell<T>`. Theres also
`Mutex<T>`, which offers interior mutability thats safe to use across threads;
well discuss its use in Chapter 16. Check out the standard library docs for
more details on the differences between these types.
structures. Note that `RefCell<T>` does not work for multithreaded code!
`Mutex<T>` is the thread-safe version of `RefCell<T>` and well discuss
`Mutex<T>` in Chapter 16.
[wheres-the---operator]: ch05-03-method-syntax.html#wheres-the---operator