diff --git a/src/ch04-01-what-is-ownership.md b/src/ch04-01-what-is-ownership.md index 5249c2dd77..8d579b4fef 100644 --- a/src/ch04-01-what-is-ownership.md +++ b/src/ch04-01-what-is-ownership.md @@ -268,11 +268,7 @@ the memory that holds the contents of the string, a length, and a capacity. This group of data is stored on the stack. On the right is the memory on the heap that holds the contents. -Two tables: the first table contains the representation of s1 on the
-stack, consisting of its length (5), capacity (5), and a pointer to the first
-value in the second table. The second table contains the representation of the
-string data on the heap, byte by byte. +{{#include img/trpl04-01.svg}} Figure 4-1: Representation in memory of a `String` holding the value `"hello"` bound to `s1` @@ -288,9 +284,7 @@ pointer, the length, and the capacity that are on the stack. We do not copy the data on the heap that the pointer refers to. In other words, the data representation in memory looks like Figure 4-2. -Three tables: tables s1 and s2 representing those strings on the
-stack, respectively, and both pointing to the same string data on the heap. +{{#include img/trpl04-02.svg}} Figure 4-2: Representation in memory of the variable `s2` that has a copy of the pointer, length, and capacity of `s1` @@ -300,9 +294,7 @@ look like if Rust instead copied the heap data as well. If Rust did this, the operation `s2 = s1` could be very expensive in terms of runtime performance if the data on the heap were large. -Four tables: two tables representing the stack data for s1 and s2,
-and each points to its own copy of string data on the heap. +{{#include img/trpl04-03.svg}} Figure 4-3: Another possibility for what `s2 = s1` might do if Rust copied the heap data as well @@ -338,11 +330,7 @@ because Rust also invalidates the first variable, instead of being called a shallow copy, it’s known as a *move*. In this example, we would say that `s1` was *moved* into `s2`. So, what actually happens is shown in Figure 4-4. -Three tables: tables s1 and s2 representing those strings on the
-stack, respectively, and both pointing to the same string data on the heap.
-Table s1 is grayed out be-cause s1 is no longer valid; only s2 can be used to
-access the heap data. +{{#include img/trpl04-04.svg}} Figure 4-4: Representation in memory after `s1` has been invalidated diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index ea2d8d2029..83cbfca54e 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -24,9 +24,7 @@ function return value is gone. Second, note that we pass `&s1` into `String`. These ampersands represent *references*, and they allow you to refer to some value without taking ownership of it. Figure 4-5 depicts this concept. -Three tables: the table for s contains only a pointer to the table
-for s1. The table for s1 contains the stack data for s1 and points to the
-string data on the heap. +{{#include img/trpl04-05.svg}} Figure 4-5: A diagram of `&String s` pointing at `String s1` diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 6ffb1dc114..f134df34de 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -123,11 +123,7 @@ byte at index 6 of `s` with a length value of `5`. Figure 4-6 shows this in a diagram. -Three tables: a table representing the stack data of s, which points
-to the byte at index 0 in a table of the string data "hello world" on
-the heap. The third table rep-resents the stack data of the slice world, which
-has a length value of 5 and points to byte 6 of the heap data table. +{{#include img/trpl04-06.svg}} Figure 4-6: String slice referring to part of a `String` diff --git a/src/ch15-01-box.md b/src/ch15-01-box.md index 8380625527..431b1fffab 100644 --- a/src/ch15-01-box.md +++ b/src/ch15-01-box.md @@ -178,7 +178,7 @@ type needs, the compiler looks at the variants, starting with the `Cons` variant. The `Cons` variant holds a value of type `i32` and a value of type `List`, and this process continues infinitely, as shown in Figure 15-1. -An infinite Cons list +{{#include img/trpl15-01.svg}} Figure 15-1: An infinite `List` consisting of infinite `Cons` variants @@ -232,7 +232,7 @@ broken the infinite, recursive chain, so the compiler can figure out the size it needs to store a `List` value. Figure 15-2 shows what the `Cons` variant looks like now. -A finite Cons list +{{#include img/trpl15-02.svg}} Figure 15-2: A `List` that is not infinitely sized because `Cons` holds a `Box` diff --git a/src/ch15-04-rc.md b/src/ch15-04-rc.md index 87a42eb1a5..56a5dbb76c 100644 --- a/src/ch15-04-rc.md +++ b/src/ch15-04-rc.md @@ -35,7 +35,7 @@ Let’s return to our cons list example in Listing 15-5. Recall that we defined it using `Box`. This time, we’ll create two lists that both share ownership of a third list. Conceptually, this looks similar to Figure 15-3: -Two lists that share ownership of a third list +{{#include img/trpl15-03.svg}} Figure 15-3: Two lists, `b` and `c`, sharing ownership of a third list, `a` diff --git a/src/ch15-06-reference-cycles.md b/src/ch15-06-reference-cycles.md index beb2bc2169..e64a3087b2 100644 --- a/src/ch15-06-reference-cycles.md +++ b/src/ch15-06-reference-cycles.md @@ -75,7 +75,7 @@ well. This instance’s memory can’t be dropped either, because the other remain uncollected forever. To visualize this reference cycle, we’ve created a diagram in Figure 15-4. -Reference cycle of lists +{{#include img/trpl15-04.svg}} Figure 15-4: A reference cycle of lists `a` and `b` pointing to each other diff --git a/src/img/trpl04-01.svg b/src/img/trpl04-01.svg index 314f53ba12..ae9e9f9667 100644 --- a/src/img/trpl04-01.svg +++ b/src/img/trpl04-01.svg @@ -1,68 +1,62 @@ - - - - - - -%3 - - - -table0 - -s1 - -name - -value - -ptr - - -len - -5 - -capacity - -5 - - - -table1 - -index - -value - -0 - -h - -1 - -e - -2 - -l - -3 - -l - -4 - -o - - - -table0:c->table1:pointee - - - - - + + + Figure 4-1 + + + table0 + + s1 + + name + + value + + ptr + + + len + + 5 + + capacity + + 5 + + + table1 + + index + + value + + 0 + + h + + 1 + + e + + 2 + + l + + 3 + + l + + 4 + + o + + + table0:c->table1:pointee + + + + + \ No newline at end of file diff --git a/src/img/trpl04-02.svg b/src/img/trpl04-02.svg index 70d490f0bc..d76f6b2335 100644 --- a/src/img/trpl04-02.svg +++ b/src/img/trpl04-02.svg @@ -1,95 +1,85 @@ - - - - - - -%3 - - - -table0 - -s1 - -name - -value - -ptr - - -len - -5 - -capacity - -5 - - - -table1 - -index - -value - -0 - -h - -1 - -e - -2 - -l - -3 - -l - -4 - -o - - - -table0:c->table1:pointee - - - - - -table3 - -s2 - -name - -value - -ptr - - -len - -5 - -capacity - -5 - - - -table3:c->table1:pointee - - - - - + + + Figure 4-2 + + + table0 + + s1 + + name + + value + + ptr + + + len + + 5 + + capacity + + 5 + + + table1 + + index + + value + + 0 + + h + + 1 + + e + + 2 + + l + + 3 + + l + + 4 + + o + + + table0:c->table1:pointee + + + + + table3 + + s2 + + name + + value + + ptr + + + len + + 5 + + capacity + + 5 + + + table3:c->table1:pointee + + + + + \ No newline at end of file diff --git a/src/img/trpl04-03.svg b/src/img/trpl04-03.svg index 7c153e23a3..b13911a7b5 100644 --- a/src/img/trpl04-03.svg +++ b/src/img/trpl04-03.svg @@ -1,123 +1,112 @@ - - - - - - -%3 - - - -table0 - -s2 - -name - -value - -ptr - - -len - -5 - -capacity - -5 - - - -table1 - -index - -value - -0 - -h - -1 - -e - -2 - -l - -3 - -l - -4 - -o - - - -table0:c->table1:pointee - - - - - -table3 - -s1 - -name - -value - -ptr - - -len - -5 - -capacity - -5 - - - -table4 - -index - -value - -0 - -h - -1 - -e - -2 - -l - -3 - -l - -4 - -o - - - -table3:c->table4:pointee - - - - - + + + Figure 4-3 + + + table0 + + s2 + + name + + value + + ptr + + + len + + 5 + + capacity + + 5 + + + table1 + + index + + value + + 0 + + h + + 1 + + e + + 2 + + l + + 3 + + l + + 4 + + o + + + table0:c->table1:pointee + + + + + table3 + + s1 + + name + + value + + ptr + + + len + + 5 + + capacity + + 5 + + + table4 + + index + + value + + 0 + + h + + 1 + + e + + 2 + + l + + 3 + + l + + 4 + + o + + + table3:c->table4:pointee + + + + + \ No newline at end of file diff --git a/src/img/trpl04-04.svg b/src/img/trpl04-04.svg index a0513abd90..bb55e6fcab 100644 --- a/src/img/trpl04-04.svg +++ b/src/img/trpl04-04.svg @@ -1,96 +1,87 @@ - - - - - - -%3 - - - -table0 - - -s1 - -name - -value - -ptr - - -len - -5 - -capacity - -5 - - - -table1 - -index - -value - -0 - -h - -1 - -e - -2 - -l - -3 - -l - -4 - -o - - - -table0:c->table1:pointee - - - - - -table3 - -s2 - -name - -value - -ptr - - -len - -5 - -capacity - -5 - - - -table3:c->table1:pointee - - - - - + + + Figure 4-4 + + + table0 + + s1 + + name + + value + + ptr + + + len + + 5 + + capacity + + 5 + + + table1 + + index + + value + + 0 + + h + + 1 + + e + + 2 + + l + + 3 + + l + + 4 + + o + + + table0:c->table1:pointee + + + + + table3 + + s2 + + name + + value + + ptr + + + len + + 5 + + capacity + + 5 + + + table3:c->table1:pointee + + + + + \ No newline at end of file diff --git a/src/img/trpl04-05.svg b/src/img/trpl04-05.svg index b4bf2ebee8..290defb8b9 100644 --- a/src/img/trpl04-05.svg +++ b/src/img/trpl04-05.svg @@ -1,87 +1,78 @@ - - - - - - -%3 - - - -table0 - -s - -name - -value - -ptr - - - - -table1 - -s1 - -name - -value - -ptr - - -len - -5 - -capacity - -5 - - - -table0:c->table1:borrowee - - - - - -table2 - -index - -value - -0 - -h - -1 - -e - -2 - -l - -3 - -l - -4 - -o - - - -table1:c->table2:pointee - - - - - + + + Figure 4-5 + + + table0 + + s + + name + + value + + ptr + + + + table1 + + s1 + + name + + value + + ptr + + + len + + 5 + + capacity + + 5 + + + table0:c->table1:borrowee + + + + + table2 + + index + + value + + 0 + + h + + 1 + + e + + 2 + + l + + 3 + + l + + 4 + + o + + + table1:c->table2:pointee + + + + + \ No newline at end of file diff --git a/src/img/trpl04-06.svg b/src/img/trpl04-06.svg index e64415fe43..f3821cc177 100644 --- a/src/img/trpl04-06.svg +++ b/src/img/trpl04-06.svg @@ -1,115 +1,107 @@ - - - - - - -%3 - - - -table0 - -world - -name - -value - -ptr - - -len - -5 - - - -table4 - -index - -value - -0 - -h - -1 - -e - -2 - -l - -3 - -l - -4 - -o - -5 - - - -6 - -w - -7 - -o - -8 - -r - -9 - -l - -10 - -d - - - -table0:c->table4:pointee2 - - - - - -table3 - -s - -name - -value - -ptr - - -len - -11 - -capacity - -11 - - - -table3:c->table4:pointee - - - - - + + + Figure 4-6 + + + table0 + + world + + name + + value + + ptr + + + len + + 5 + + + table4 + + index + + value + + 0 + + h + + 1 + + e + + 2 + + l + + 3 + + l + + 4 + + o + + 5 + + + + 6 + + w + + 7 + + o + + 8 + + r + + 9 + + l + + 10 + + d + + + table0:c->table4:pointee2 + + + + + table3 + + s + + name + + value + + ptr + + + len + + 11 + + capacity + + 11 + + + table3:c->table4:pointee + + + + + \ No newline at end of file diff --git a/src/img/trpl15-01.svg b/src/img/trpl15-01.svg index bbeef968a2..992d505eef 100644 --- a/src/img/trpl15-01.svg +++ b/src/img/trpl15-01.svg @@ -1,43 +1,35 @@ - - - - - - -%3 - - - -table0 - -Cons - -i32 - - -Cons - -i32 - - -Cons - -i32 - - -Cons - -i32 - - -Cons - -i32 - - - - - + + + Figure 15-1 + + + table0 + + Cons + + i32 + + + Cons + + i32 + + + Cons + + i32 + + + Cons + + i32 + + + Cons + + i32 + + + + + \ No newline at end of file diff --git a/src/img/trpl15-02.svg b/src/img/trpl15-02.svg index 4454df8c38..21b4a89091 100644 --- a/src/img/trpl15-02.svg +++ b/src/img/trpl15-02.svg @@ -1,26 +1,18 @@ - - - - - - -%3 - - - -table0 - -Cons - -i32 - - -Box - -usize - - - + + + Figure 15-2 + + + table0 + + Cons + + i32 + + + Box + + usize + + + \ No newline at end of file diff --git a/src/img/trpl15-03.svg b/src/img/trpl15-03.svg index dbc3b5cdb0..4616f3dc48 100644 --- a/src/img/trpl15-03.svg +++ b/src/img/trpl15-03.svg @@ -1,109 +1,86 @@ - - - - - - -%3 - - - -table4 -b - - - -table5 - -3 - -   - - - -table4:c->table5:pte4 - - - - - -table1 - -5 - -   - - - -table5:c->table1:pte0 - - - - - -table0 -a - - - -table0:c->table1:pte0 - - - - - -table2 - -10 - -   - - - -table1:c->table2:pte1 - - - - - -table3 - -Nil - - - -table2:c->table3:pte2 - - - - - -table6 -c - - - -table7 - -4 - -   - - - -table6:c->table7:pte6 - - - - - -table7:c->table1:pte0 - - - - - + + + Figure 15-3 + + + table4 + b + + + table5 + + 3 + +   + + + table4:c->table5:pte4 + + + + + table1 + + 5 + +   + + + table5:c->table1:pte0 + + + + + table0 + a + + + table0:c->table1:pte0 + + + + + table2 + + 10 + +   + + + table1:c->table2:pte1 + + + + + table3 + + Nil + + + table2:c->table3:pte2 + + + + + table6 + c + + + table7 + + 4 + +   + + + table6:c->table7:pte6 + + + + + table7:c->table1:pte0 + + + + + \ No newline at end of file diff --git a/src/img/trpl15-04.svg b/src/img/trpl15-04.svg index 7285ae6735..dfb65391aa 100644 --- a/src/img/trpl15-04.svg +++ b/src/img/trpl15-04.svg @@ -1,84 +1,51 @@ - - - - - - - - - -l1 - -5 - - - - - -l2 - -10 - - - - - -l1:c->l2:data - - - - - -invisible_end - - - - -l2:c->invisible_end:n - - - - -invisible_start - - - - -invisible_start:n->l1 - - - - - -invisible_start:s->invisible_end:s - - - - -a - -a - - - -a->l1:n - - - - - -b - -b - - - -b->l2:n - - - - - + + + Figure 15-4 + + + l1 + + 5 + + + + + l2 + + 10 + + + + + l1:c->l2:data + + + + + l2:c->l1 + + + + + a + + a + + + a->l1:n + + + + + b + + b + + + b->l2:n + + + + + \ No newline at end of file