book
book copied to clipboard
Use concrete names for concrete lifetimes in ch10-03
At the start of chapter 10-03, the concept of a "lifetime" is introduced, by talking about the concrete lifetimes of values. These lifetimes are referred to using 'a
and 'b
. This can be confusing, since these names are usually used for generic lifetimes. The difference between generic lifetimes and concrete lifetimes may not be obvious, so don't make it less obvious by using generic names for the concrete lifetimes.
The names are up to debate, I've chosen 'outer_scope
and 'inner_scope
for the nested scope example, and 'full_scope
and 'partial_scope
for the example where both are in the same scope.
I'm not sure this change makes it better. There's nothing stopping anyone from naming their generic lifetimes something like 'inner_scope
; longer, more descriptive names for lifetime parameters isn't common but it does happen (and personally, I rather like more descriptive names).
What if there wasn't a '
at all? Or underscores? So that the diagrams were just labeled "inner scope" and "outer scope"? Would that make these diagrams clearer or less clear for you?
The point of this change was, that 'a
is what's used for a generic lifetime in the book, so not using the generic lifetime name for a concrete lifetime here might help to disambiguate the two. It's been a year since I learned Rust and a can't remember it exactly, but I think lifetime annotations like this were one of the more difficult things to learn, and I was confused by what fn foo<'a>
exactly means.
I'm unsure on whether removing '
makes it better. On one hand, it makes the difference between a generic lifetime parameter and an actual lifetime even clearer, but maybe it's too much?
But I think removing it is worth a try.