Skip to content

Commit e82cd3f

Browse files
committed
Chapter 10 - Wrap all <Listing>s to comply with the virtual 80 character limit
More infos and concerns can be found in the equivalent commit in the chapter 6 PR. (Had to fix a conflict here)
1 parent 9151143 commit e82cd3f

File tree

4 files changed

+56
-25
lines changed

4 files changed

+56
-25
lines changed

src/ch10-00-generics.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ duplicated code that can use generics.
4242
We’ll begin with the short program in Listing 10-1 that finds the largest
4343
number in a list.
4444

45-
<Listing number="10-1" file-name="src/main.rs" caption="Finding the largest number in a list of numbers">
45+
<Listing number="10-1" file-name="src/main.rs" caption="Finding the largest
46+
number in a list of numbers">
4647

4748
```rust
4849
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-01/src/main.rs:here}}
@@ -63,7 +64,8 @@ We’ve now been tasked with finding the largest number in two different lists o
6364
numbers. To do so, we can choose to duplicate the code in Listing 10-1 and use
6465
the same logic at two different places in the program, as shown in Listing 10-2.
6566

66-
<Listing number="10-2" file-name="src/main.rs" caption="Code to find the largest number in *two* lists of numbers">
67+
<Listing number="10-2" file-name="src/main.rs" caption="Code to find the
68+
largest number in *two* lists of numbers">
6769

6870
```rust
6971
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-02/src/main.rs}}
@@ -85,7 +87,8 @@ function named `largest`. Then we call the function to find the largest number
8587
in the two lists from Listing 10-2. We could also use the function on any other
8688
list of `i32` values we might have in the future.
8789

88-
<Listing number="10-3" file-name="src/main.rs" caption="Abstracted code to find the largest number in two lists">
90+
<Listing number="10-3" file-name="src/main.rs" caption="Abstracted code to find
91+
the largest number in two lists">
8992

9093
```rust
9194
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-03/src/main.rs:here}}

src/ch10-01-syntax.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Continuing with our `largest` function, Listing 10-4 shows two functions that
1616
both find the largest value in a slice. We’ll then combine these into a single
1717
function that uses generics.
1818

19-
<Listing number="10-4" file-name="src/main.rs" caption="Two functions that differ only in their names and in the types in their signatures">
19+
<Listing number="10-4" file-name="src/main.rs" caption="Two functions that
20+
differ only in their names and in the types in their signatures">
2021

2122
```rust
2223
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-04/src/main.rs:here}}
@@ -57,7 +58,8 @@ data type in its signature. The listing also shows how we can call the function
5758
with either a slice of `i32` values or `char` values. Note that this code won’t
5859
compile yet, but we’ll fix it later in this chapter.
5960

60-
<Listing number="10-5" file-name="src/main.rs" caption="The `largest` function using generic type parameters; this doesn’t compile yet">
61+
<Listing number="10-5" file-name="src/main.rs" caption="The `largest` function
62+
using generic type parameters; this doesn’t compile yet">
6163

6264
```rust,ignore,does_not_compile
6365
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/src/main.rs}}
@@ -88,7 +90,8 @@ We can also define structs to use a generic type parameter in one or more
8890
fields using the `<>` syntax. Listing 10-6 defines a `Point<T>` struct to hold
8991
`x` and `y` coordinate values of any type.
9092

91-
<Listing number="10-6" file-name="src/main.rs" caption="A `Point<T>` struct that holds `x` and `y` values of type `T`">
93+
<Listing number="10-6" file-name="src/main.rs" caption="A `Point<T>` struct
94+
that holds `x` and `y` values of type `T`">
9295

9396
```rust
9497
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-06/src/main.rs}}
@@ -108,7 +111,8 @@ the fields `x` and `y` are *both* that same type, whatever that type may be. If
108111
we create an instance of a `Point<T>` that has values of different types, as in
109112
Listing 10-7, our code won’t compile.
110113

111-
<Listing number="10-7" file-name="src/main.rs" caption="The fields `x` and `y` must be the same type because both have the same generic data type `T`.">
114+
<Listing number="10-7" file-name="src/main.rs" caption="The fields `x` and `y`
115+
must be the same type because both have the same generic data type `T`.">
112116

113117
```rust,ignore,does_not_compile
114118
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/src/main.rs}}
@@ -130,7 +134,8 @@ different types, we can use multiple generic type parameters. For example, in
130134
Listing 10-8, we change the definition of `Point` to be generic over types `T`
131135
and `U` where `x` is of type `T` and `y` is of type `U`.
132136

133-
<Listing number="10-8" file-name="src/main.rs" caption="A `Point<T, U>` generic over two types so that `x` and `y` can be values of different types">
137+
<Listing number="10-8" file-name="src/main.rs" caption="A `Point<T, U>` generic
138+
over two types so that `x` and `y` can be values of different types">
134139

135140
```rust
136141
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-08/src/main.rs}}
@@ -193,7 +198,9 @@ We can implement methods on structs and enums (as we did in Chapter 5) and use
193198
generic types in their definitions too. Listing 10-9 shows the `Point<T>`
194199
struct we defined in Listing 10-6 with a method named `x` implemented on it.
195200

196-
<Listing number="10-9" file-name="src/main.rs" caption="Implementing a method named `x` on the `Point<T>` struct that will return a reference to the `x` field of type `T`">
201+
<Listing number="10-9" file-name="src/main.rs" caption="Implementing a method
202+
named `x` on the `Point<T>` struct that will return a reference to the `x`
203+
field of type `T`">
197204

198205
```rust
199206
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-09/src/main.rs}}
@@ -219,7 +226,9 @@ type. We could, for example, implement methods only on `Point<f32>` instances
219226
rather than on `Point<T>` instances with any generic type. In Listing 10-10 we
220227
use the concrete type `f32`, meaning we don’t declare any types after `impl`.
221228

222-
<Listing number="10-10" file-name="src/main.rs" caption="An `impl` block that only applies to a struct with a particular concrete type for the generic type parameter `T`">
229+
<Listing number="10-10" file-name="src/main.rs" caption="An `impl` block that
230+
only applies to a struct with a particular concrete type for the generic type
231+
parameter `T`">
223232

224233
```rust
225234
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-10/src/main.rs:here}}
@@ -240,7 +249,8 @@ signature to make the example clearer. The method creates a new `Point`
240249
instance with the `x` value from the `self` `Point` (of type `X1`) and the `y`
241250
value from the passed-in `Point` (of type `Y2`).
242251

243-
<Listing number="10-11" file-name="src/main.rs" caption="A method that uses generic types different from its struct’s definition">
252+
<Listing number="10-11" file-name="src/main.rs" caption="A method that uses
253+
generic types different from its struct’s definition">
244254

245255
```rust
246256
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-11/src/main.rs}}

src/ch10-02-traits.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ instance. To do this, we need a summary from each type, and we’ll request that
2727
summary by calling a `summarize` method on an instance. Listing 10-12 shows the
2828
definition of a public `Summary` trait that expresses this behavior.
2929

30-
<Listing number="10-12" file-name="src/lib.rs" caption="A `Summary` trait that consists of the behavior provided by a `summarize` method">
30+
<Listing number="10-12" file-name="src/lib.rs" caption="A `Summary` trait that
31+
consists of the behavior provided by a `summarize` method">
3132

3233
```rust,noplayground
3334
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-12/src/lib.rs}}
@@ -61,7 +62,8 @@ the headline, the author, and the location to create the return value of
6162
followed by the entire text of the tweet, assuming that the tweet content is
6263
already limited to 280 characters.
6364

64-
<Listing number="10-13" file-name="src/lib.rs" caption="Implementing the `Summary` trait on the `NewsArticle` and `Tweet` types">
65+
<Listing number="10-13" file-name="src/lib.rs" caption="Implementing the
66+
`Summary` trait on the `NewsArticle` and `Tweet` types">
6567

6668
```rust,noplayground
6769
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-13/src/lib.rs:here}}
@@ -122,7 +124,8 @@ In Listing 10-14, we specify a default string for the `summarize` method of the
122124
`Summary` trait instead of only defining the method signature, as we did in
123125
Listing 10-12.
124126

125-
<Listing number="10-14" file-name="src/lib.rs" caption="Defining a `Summary` trait with a default implementation of the `summarize` method">
127+
<Listing number="10-14" file-name="src/lib.rs" caption="Defining a `Summary`
128+
trait with a default implementation of the `summarize` method">
126129

127130
```rust,noplayground
128131
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-14/src/lib.rs:here}}
@@ -336,7 +339,8 @@ is a type alias for the type of the `impl` block, which in this case is
336339
`cmp_display` method if its inner type `T` implements the `PartialOrd` trait
337340
that enables comparison *and* the `Display` trait that enables printing.
338341

339-
<Listing number="10-15" file-name="src/lib.rs" caption="Conditionally implementing methods on a generic type depending on trait bounds">
342+
<Listing number="10-15" file-name="src/lib.rs" caption="Conditionally
343+
implementing methods on a generic type depending on trait bounds">
340344

341345
```rust,noplayground
342346
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-15/src/lib.rs}}

src/ch10-03-lifetime-syntax.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ program to reference data other than the data it’s intended to reference.
2626
Consider the program in Listing 10-16, which has an outer scope and an inner
2727
scope.
2828

29-
<Listing number="10-16" caption="An attempt to use a reference whose value has gone out of scope">
29+
<Listing number="10-16" caption="An attempt to use a reference whose value has
30+
gone out of scope">
3031

3132
```rust,ignore,does_not_compile
3233
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/src/main.rs}}
@@ -66,7 +67,8 @@ The Rust compiler has a *borrow checker* that compares scopes to determine
6667
whether all borrows are valid. Listing 10-17 shows the same code as Listing
6768
10-16 but with annotations showing the lifetimes of the variables.
6869

69-
<Listing number="10-17" caption="Annotations of the lifetimes of `r` and `x`, named `'a` and `'b`, respectively">
70+
<Listing number="10-17" caption="Annotations of the lifetimes of `r` and `x`,
71+
named `'a` and `'b`, respectively">
7072

7173
```rust,ignore,does_not_compile
7274
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-17/src/main.rs}}
@@ -84,7 +86,8 @@ with a lifetime of `'b`. The program is rejected because `'b` is shorter than
8486
Listing 10-18 fixes the code so it doesn’t have a dangling reference and it
8587
compiles without any errors.
8688

87-
<Listing number="10-18" caption="A valid reference because the data has a longer lifetime than the reference">
89+
<Listing number="10-18" caption="A valid reference because the data has a
90+
longer lifetime than the reference">
8891

8992
```rust
9093
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-18/src/main.rs}}
@@ -107,7 +110,8 @@ function will take two string slices and return a single string slice. After
107110
we’ve implemented the `longest` function, the code in Listing 10-19 should
108111
print `The longest string is abcd`.
109112

110-
<Listing number="10-19" file-name="src/main.rs" caption="A `main` function that calls the `longest` function to find the longer of two string slices">
113+
<Listing number="10-19" file-name="src/main.rs" caption="A `main` function that
114+
calls the `longest` function to find the longer of two string slices">
111115

112116
```rust,ignore
113117
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-19/src/main.rs}}
@@ -125,7 +129,9 @@ ones we want.
125129
If we try to implement the `longest` function as shown in Listing 10-20, it
126130
won’t compile.
127131

128-
<Listing number="10-20" file-name="src/main.rs" caption="An implementation of the `longest` function that returns the longer of two string slices but does not yet compile">
132+
<Listing number="10-20" file-name="src/main.rs" caption="An implementation of
133+
the `longest` function that returns the longer of two string slices but does
134+
not yet compile">
129135

130136
```rust,ignore,does_not_compile
131137
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/src/main.rs:here}}
@@ -197,7 +203,9 @@ relationship between lifetimes of the parameters and the return value. We’ll
197203
name the lifetime `'a` and then add it to each reference, as shown in Listing
198204
10-21.
199205

200-
<Listing number="10-21" file-name="src/main.rs" caption="The `longest` function definition specifying that all the references in the signature must have the same lifetime `'a`">
206+
<Listing number="10-21" file-name="src/main.rs" caption="The `longest` function
207+
definition specifying that all the references in the signature must have the
208+
same lifetime `'a`">
201209

202210
```rust
203211
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-21/src/main.rs:here}}
@@ -247,7 +255,9 @@ Let’s look at how the lifetime annotations restrict the `longest` function by
247255
passing in references that have different concrete lifetimes. Listing 10-22 is
248256
a straightforward example.
249257

250-
<Listing number="10-22" file-name="src/main.rs" caption="Using the `longest` function with references to `String` values that have different concrete lifetimes">
258+
<Listing number="10-22" file-name="src/main.rs" caption="Using the `longest`
259+
function with references to `String` values that have different concrete
260+
lifetimes">
251261

252262
```rust
253263
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-22/src/main.rs:here}}
@@ -269,7 +279,8 @@ assignment of the value to the `result` variable inside the scope with
269279
inner scope, after the inner scope has ended. The code in Listing 10-23 will
270280
not compile.
271281

272-
<Listing number="10-23" file-name="src/main.rs" caption="Attempting to use `result` after `string2` has gone out of scope">
282+
<Listing number="10-23" file-name="src/main.rs" caption="Attempting to use
283+
`result` after `string2` has gone out of scope">
273284

274285
```rust,ignore,does_not_compile
275286
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/src/main.rs:here}}
@@ -367,7 +378,8 @@ to hold references, but in that case we would need to add a lifetime annotation
367378
on every reference in the struct’s definition. Listing 10-24 has a struct named
368379
`ImportantExcerpt` that holds a string slice.
369380

370-
<Listing number="10-24" file-name="src/main.rs" caption="A struct that holds a reference, requiring a lifetime annotation">
381+
<Listing number="10-24" file-name="src/main.rs" caption="A struct that holds a
382+
reference, requiring a lifetime annotation">
371383

372384
```rust
373385
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-24/src/main.rs}}
@@ -396,7 +408,9 @@ lifetime parameters for functions or structs that use references. However, we
396408
had a function in Listing 4-9, shown again in Listing 10-25, that compiled
397409
without lifetime annotations.
398410

399-
<Listing number="10-25" file-name="src/lib.rs" caption="A function we defined in Listing 4-9 that compiled without lifetime annotations, even though the parameter and return type are references">
411+
<Listing number="10-25" file-name="src/lib.rs" caption="A function we defined
412+
in Listing 4-9 that compiled without lifetime annotations, even though the
413+
parameter and return type are references">
400414

401415
```rust
402416
{{#rustdoc_include ../listings/ch10-generic-types-traits-and-lifetimes/listing-10-25/src/main.rs:here}}

0 commit comments

Comments
 (0)