You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -193,7 +198,9 @@ We can implement methods on structs and enums (as we did in Chapter 5) and use
193
198
generic types in their definitions too. Listing 10-9 shows the `Point<T>`
194
199
struct we defined in Listing 10-6 with a method named `x` implemented on it.
195
200
196
-
<Listingnumber="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`
@@ -219,7 +226,9 @@ type. We could, for example, implement methods only on `Point<f32>` instances
219
226
rather than on `Point<T>` instances with any generic type. In Listing 10-10 we
220
227
use the concrete type `f32`, meaning we don’t declare any types after `impl`.
221
228
222
-
<Listingnumber="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
If we try to implement the `longest` function as shown in Listing 10-20, it
126
130
won’t compile.
127
131
128
-
<Listingnumber="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
@@ -197,7 +203,9 @@ relationship between lifetimes of the parameters and the return value. We’ll
197
203
name the lifetime `'a` and then add it to each reference, as shown in Listing
198
204
10-21.
199
205
200
-
<Listingnumber="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
@@ -247,7 +255,9 @@ Let’s look at how the lifetime annotations restrict the `longest` function by
247
255
passing in references that have different concrete lifetimes. Listing 10-22 is
248
256
a straightforward example.
249
257
250
-
<Listingnumber="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
@@ -396,7 +408,9 @@ lifetime parameters for functions or structs that use references. However, we
396
408
had a function in Listing 4-9, shown again in Listing 10-25, that compiled
397
409
without lifetime annotations.
398
410
399
-
<Listingnumber="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
0 commit comments