diff --git a/dot/trpl04-05.dot b/dot/trpl04-05.dot new file mode 100644 index 0000000..55aa221 --- /dev/null +++ b/dot/trpl04-05.dot @@ -0,0 +1,31 @@ +digraph { + rankdir=LR; + dpi=300.0; + node [shape="plaintext"]; + + table0[label=< + + + +
s
namevalue
ptr
>]; + table1[label=< + + + + + +
s1
namevalue
ptr
len5
capacity5
>]; + table2[label=< + + + + + + +
indexvalue
0h
1e
2l
3l
4o
>]; + + edge[tailclip="false"]; + table1:pointer:c -> table2:pointee; + table0:borrower:c -> table1:borrowee; +} + diff --git a/dot/trpl04-06.dot b/dot/trpl04-06.dot new file mode 100644 index 0000000..6a92e9c --- /dev/null +++ b/dot/trpl04-06.dot @@ -0,0 +1,40 @@ +digraph { + rankdir=LR; + dpi=300.0; + node [shape="plaintext"]; + + table0[label=< + + + + +
world
namevalue
ptr
len5
>]; + + table3[label=< + + + + + +
s
namevalue
ptr
len5
capacity5
>]; + table4[label=< + + + + + + + + + + + + +
indexvalue
0h
1e
2l
3l
4o
5
6w
7o
8r
9l
10d
>]; + + + edge[tailclip="false"]; + table0:pointer2:c -> table4:pointee2; + table3:pointer:c -> table4:pointee; +} + diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index 2861f6e..47ad307 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -53,7 +53,7 @@ function return value is gone. Next, note that we pass `&s1` into These `&`s are called *references*, and they allow you to refer to some value without taking ownership of it. Here’s a diagram: -DIAGRAM GOES HERE of a &String pointing at a String, with (ptr, len, capacity) +&String s pointing at String s1 Let’s take a closer look at the function call here: diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 40512d6..b1395b1 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -141,7 +141,7 @@ contains a pointer to the 6th byte of `s` and a length value of 5. In other words, it looks like this: -DIAGRAM GOES HERE of s, hello, and world +world containing a pointer to the 6th byte of String s and a length 5 With Rust’s `..` 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: diff --git a/src/img/trpl04-05.svg b/src/img/trpl04-05.svg new file mode 100644 index 0000000..33e5b49 --- /dev/null +++ b/src/img/trpl04-05.svg @@ -0,0 +1,82 @@ + + + + + + +%3 + + +table0 + +s + +name + +value + +ptr + + + +table1 + +s1 + +name + +value + +ptr + + +len + +5 + +capacity + +5 + + +table0:borrower:c->table1:borrowee + + + + +table2 + +index + +value + +0 + +h + +1 + +e + +2 + +l + +3 + +l + +4 + +o + + +table1:pointer:c->table2:pointee + + + + + diff --git a/src/img/trpl04-06.svg b/src/img/trpl04-06.svg new file mode 100644 index 0000000..16510b1 --- /dev/null +++ b/src/img/trpl04-06.svg @@ -0,0 +1,110 @@ + + + + + + +%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:pointer2:c->table4:pointee2 + + + + +table3 + +s + +name + +value + +ptr + + +len + +5 + +capacity + +5 + + +table3:pointer:c->table4:pointee + + + + +