Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions nostarch/chapter08.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ Listing 8-8: Iterating over mutable references to elements in a vector
To change the value that the mutable reference refers to, we have to use the
`*` dereference operator to get to the value in `i` before we can use the `+=`
operator. We’ll talk more about the dereference operator in the “Following the
Pointer to the Value” section of Chapter 15.
Reference to the Value” section of Chapter 15.

Iterating over a vector, whether immutably or mutably, is safe because of the
borrow checker’s rules. If we attempted to insert or remove items in the `for`
Expand Down Expand Up @@ -584,7 +584,7 @@ get an error. Consider the invalid code in Listing 8-19.


```
let s1 = String::from("hello");
let s1 = String::from("hi");
let h = s1[0];
```

Expand All @@ -601,10 +601,10 @@ error[E0277]: the type `str` cannot be indexed by `{integer}`
3 | let h = s1[0];
| ^ string indices are ranges of `usize`
|
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`, which is required by `String: Index<_>`
= note: you can use `.chars().nth()` or `.bytes().nth()`
for more information, see chapter 8 in The Book: <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
= help: the trait `SliceIndex<[_]>` is implemented for `usize`
= help: the trait `SliceIndex<str>` is not implemented for `{integer}`
but trait `SliceIndex<[_]>` is implemented for `usize`
= help: for that trait implementation, expected `[_]`, found `str`
= note: required for `String` to implement `Index<{integer}>`

Expand Down Expand Up @@ -729,6 +729,7 @@ $ cargo run
Compiling collections v0.1.0 (file:///projects/collections)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s
Running `target/debug/collections`

thread 'main' panicked at src/main.rs:4:19:
byte index 1 is not a char boundary; it is inside 'З' (bytes 0..2) of `Здравствуйте`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expand Down
Binary file modified nostarch/docx/chapter08.docx
Binary file not shown.
2 changes: 1 addition & 1 deletion src/ch08-01-vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ will add `50` to each element.
To change the value that the mutable reference refers to, we have to use the
`*` dereference operator to get to the value in `i` before we can use the `+=`
operator. We’ll talk more about the dereference operator in the [“Following the
Pointer to the Value”][deref]<!-- ignore --> section of Chapter 15.
Reference to the Value”][deref]<!-- ignore --> section of Chapter 15.

Iterating over a vector, whether immutably or mutably, is safe because of the
borrow checker’s rules. If we attempted to insert or remove items in the `for`
Expand Down
5 changes: 3 additions & 2 deletions src/ch15-02-deref.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ or smart pointers.
> We are focusing this example on `Deref`, so where the data is actually stored
> is less important than the pointer-like behavior.

<!-- Old link, do not remove -->
<!-- Old links, do not remove -->

<a id="following-the-pointer-to-the-value-with-the-dereference-operator"></a>
<a id="following-the-pointer-to-the-value"></a>

### Following the Pointer to the Value
### Following the Reference to the Value

A regular reference is a type of pointer, and one way to think of a pointer is
as an arrow to a value stored somewhere else. In Listing 15-6, we create a
Expand Down