So, lifetime parameters seem to be a big source of confusion for new Rustaceans; I don’t think that’s news to anyone. And I’m sure better documentation will be coming at some point. But I know that people who have gained a thorough understanding of a difficult topic often lose sight of how the topic is difficult for others. So I just want to outline the points that I personally feel need clarification. I think some of these things are already somewhat documented, but may need to be stated more explicitly or illustrated with examples.
- Is a lifetime parameter an order to the compiler, or just a suggestion?
- It is self-evident that a lifetime has a beginning and an end. But what exactly does a lifetime parameter (in a given position in the code) say about that beginning and end?
- When an object or function has multiple lifetimes associated with it (e.g. a struct type containing members with different lifetimes), does one lifetime take precedence over others? Is there a straightforward way to determine which one that is?
- When a lifetime is declared in a particular context (e.g. a function signature), how does that affect the behavior of the associated objects in other contexts (e.g. in the calling function).
- Is it possible to state any general guidelines about where lifetimes should be declared and to which objects they should be attached?
That’s my list. Maybe other folks have more?