Fix merging of figures

This commit is contained in:
Carol (Nichols || Goulding) 2016-09-08 18:12:10 -04:00
parent d26cdc7508
commit e4ddcabf6f
3 changed files with 7 additions and 2 deletions

View File

@ -261,6 +261,7 @@ length, and a capacity. This group of data is stored on the stack. On the right
is the memory that holds the contents, and this is on the heap.
<img alt="String in memory" src="img/trpl04-01.svg" class="center" style="width: 50%;" />
Figure 4-1: Representation in memory of a `String` holding the value "hello"
bound to `s1`
@ -276,6 +277,7 @@ copy the data on the heap that the `String`'s pointer refers to. In other
words, it looks like figure 4-2.
<img alt="s1 and s2 pointing to the same value" src="img/trpl04-02.svg" class="center" style="width: 50%;" />
Figure 4-2: Representation in memory of the binding `s2` that has a copy of
`s1`'s pointer, length and capacity
@ -329,6 +331,7 @@ it's known as a _move_. Here we would read this by saying that `s1` was _moved_
into `s2`. So what actually happens looks like Figure 4-4.
<img alt="s1 moved to s2" src="img/trpl04-04.svg" class="center" style="width: 50%;" />
Figure 4-4: Representation in memory after `s1` has been invalidated
That solves our problem! With only `s2` valid, when it goes out of scope, it

View File

@ -35,6 +35,7 @@ These `&`s are *references*, and they allow you to refer to some value
without taking ownership of it. Figure 4-5 shows a diagram of this.
<img alt="&String s pointing at String s1" src="img/trpl04-05.svg" class="center" />
Figure 4-5: `&String s` pointing at `String s1`
Lets take a closer look at the function call here:

View File

@ -148,10 +148,11 @@ slice data structure actually stores the starting position and the length of the
slice. So in the case of `let world = &s[6..11];`, `world` would be a slice that
contains a pointer to the 6th byte of `s` and a length value of 5.
Figure 4-7 shows this in a diagram:
Figure 4-6 shows this in a diagram:
<img alt="world containing a pointer to the 6th byte of String s and a length 5" src="img/trpl04-06.svg" class="center" style="width: 50%;" />
Figure 4-7: Two string slices referring to parts of a `String`
Figure 4-6: Two string slices referring to parts of a `String`
With Rusts `..` range syntax, if you want to start at the first index (zero),
you can drop the value before the `..`. In other words, these are equal: