Skip to content

Commit b28a2f6

Browse files
authored
Merge pull request #3977 from SpectralPixel/listing-preprocessor-chapter-06
Convert Listings in Chapter 06 to `<Listing>`
2 parents 2399b90 + fd14508 commit b28a2f6

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/ch06-01-defining-an-enum.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ only know what *kind* it is. Given that you just learned about structs in
5959
Chapter 5, you might be tempted to tackle this problem with structs as shown in
6060
Listing 6-1.
6161

62+
<Listing number="6-1" caption="Storing the data and `IpAddrKind` variant of an IP address using a `struct`">
63+
6264
```rust
6365
{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-01/src/main.rs:here}}
6466
```
6567

66-
<span class="caption">Listing 6-1: Storing the data and `IpAddrKind` variant of
67-
an IP address using a `struct`</span>
68+
</Listing>
6869

6970
Here, we’ve defined a struct `IpAddr` that has two fields: a `kind` field that
7071
is of type `IpAddrKind` (the enum we defined previously) and an `address` field
@@ -140,12 +141,13 @@ more about bringing types into scope in Chapter 7.
140141
Let’s look at another example of an enum in Listing 6-2: this one has a wide
141142
variety of types embedded in its variants.
142143

144+
<Listing number="6-2" caption="A `Message` enum whose variants each store different amounts and types of values">
145+
143146
```rust
144147
{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-02/src/main.rs:here}}
145148
```
146149

147-
<span class="caption">Listing 6-2: A `Message` enum whose variants each store
148-
different amounts and types of values</span>
150+
</Listing>
149151

150152
This enum has four variants with different types:
151153

src/ch06-02-match.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ function that takes an unknown US coin and, in a similar way as the counting
2222
machine, determines which coin it is and returns its value in cents, as shown
2323
in Listing 6-3.
2424

25+
<Listing number="6-3" caption="An enum and a `match` expression that has the variants of the enum as its patterns">
26+
2527
```rust
2628
{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-03/src/main.rs:here}}
2729
```
2830

29-
<span class="caption">Listing 6-3: An enum and a `match` expression that has
30-
the variants of the enum as its patterns</span>
31+
</Listing>
3132

3233
Let’s break down the `match` in the `value_in_cents` function. First we list
3334
the `match` keyword followed by an expression, which in this case is the value
@@ -75,12 +76,13 @@ designs, so only quarters have this extra value. We can add this information to
7576
our `enum` by changing the `Quarter` variant to include a `UsState` value
7677
stored inside it, which we’ve done in Listing 6-4.
7778

79+
<Listing number="6-4" caption="A `Coin` enum in which the `Quarter` variant also holds a `UsState` value">
80+
7881
```rust
7982
{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-04/src/main.rs:here}}
8083
```
8184

82-
<span class="caption">Listing 6-4: A `Coin` enum in which the `Quarter` variant
83-
also holds a `UsState` value</span>
85+
</Listing>
8486

8587
Let’s imagine that a friend is trying to collect all 50 state quarters. While
8688
we sort our loose change by coin type, we’ll also call out the name of the
@@ -119,12 +121,13 @@ operations.
119121
This function is very easy to write, thanks to `match`, and will look like
120122
Listing 6-5.
121123

124+
<Listing number="6-5" caption="A function that uses a `match` expression on an `Option<i32>`">
125+
122126
```rust
123127
{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-05/src/main.rs:here}}
124128
```
125129

126-
<span class="caption">Listing 6-5: A function that uses a `match` expression on
127-
an `Option<i32>`</span>
130+
</Listing>
128131

129132
Let’s examine the first execution of `plus_one` in more detail. When we call
130133
`plus_one(five)`, the variable `x` in the body of `plus_one` will have the

src/ch06-03-if-let.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ program in Listing 6-6 that matches on an `Option<u8>` value in the
66
`config_max` variable but only wants to execute code if the value is the `Some`
77
variant.
88

9+
<Listing number="6-6" caption="A `match` that only cares about executing code when the value is `Some`">
10+
911
```rust
1012
{{#rustdoc_include ../listings/ch06-enums-and-pattern-matching/listing-06-06/src/main.rs:here}}
1113
```
1214

13-
<span class="caption">Listing 6-6: A `match` that only cares about executing
14-
code when the value is `Some`</span>
15+
</Listing>
1516

1617
If the value is `Some`, we print out the value in the `Some` variant by binding
1718
the value to the variable `max` in the pattern. We don’t want to do anything

0 commit comments

Comments
 (0)