From 4275162b3f4af8ab9c80b46c5120fb41b750a7b1 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 10 Dec 2020 22:10:54 -0500 Subject: [PATCH] Explain that we do need to have 'static now --- src/ch13-03-improving-our-io-project.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ch13-03-improving-our-io-project.md b/src/ch13-03-improving-our-io-project.md index f5efc4363d..28a494500f 100644 --- a/src/ch13-03-improving-our-io-project.md +++ b/src/ch13-03-improving-our-io-project.md @@ -89,6 +89,16 @@ signature of the `Config::new` function so the parameter `args` has the type `args` and we’ll be mutating `args` by iterating over it, we can add the `mut` keyword into the specification of the `args` parameter to make it mutable. +We also needed to specify that the string slice error type can now only have +the `'static` lifetime. Because we’re only ever returning string literals, this +was true before. However, when we had a reference in the parameters, there was +the possibility that the reference in the return type could have had the same +lifetime as the reference in the parameters. The rules that we discussed in the +[“Lifetime Elision”][lifetime-elision] section of Chapter 10 applied, and we +weren’t required to annotate the lifetime of `&str`. With the change to `args`, +the lifetime elision rules no longer apply, and we must specify the `'static` +lifetime. + #### Using `Iterator` Trait Methods Instead of Indexing Next, we’ll fix the body of `Config::new`. The standard library documentation @@ -165,3 +175,5 @@ the iterator must pass. But are the two implementations truly equivalent? The intuitive assumption might be that the more low-level loop will be faster. Let’s talk about performance. + +[lifetime-elision]: ch10-03-lifetime-syntax.html#lifetime-elision