File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,16 @@ signature of the `Config::new` function so the parameter `args` has the type
8989` args ` and we’ll be mutating ` args ` by iterating over it, we can add the ` mut `
9090keyword into the specification of the ` args ` parameter to make it mutable.
9191
92+ We also needed to specify that the string slice error type can now only have
93+ the ` 'static ` lifetime. Because we’re only ever returning string literals, this
94+ was true before. However, when we had a reference in the parameters, there was
95+ the possibility that the reference in the return type could have had the same
96+ lifetime as the reference in the parameters. The rules that we discussed in the
97+ [ “Lifetime Elision”] [ lifetime-elision ] section of Chapter 10 applied, and we
98+ weren’t required to annotate the lifetime of ` &str ` . With the change to ` args ` ,
99+ the lifetime elision rules no longer apply, and we must specify the ` 'static `
100+ lifetime.
101+
92102#### Using ` Iterator ` Trait Methods Instead of Indexing
93103
94104Next, we’ll fix the body of ` Config::new ` . The standard library documentation
@@ -165,3 +175,5 @@ the iterator must pass.
165175But are the two implementations truly equivalent? The intuitive assumption
166176might be that the more low-level loop will be faster. Let’s talk about
167177performance.
178+
179+ [ lifetime-elision ] : ch10-03-lifetime-syntax.html#lifetime-elision
You can’t perform that action at this time.
0 commit comments