Some ideas off the top of my head:
- Talk about what exactly 'a means in
&'a T. For instance, it’s not necessarily the scope of where T itself is live but potentially a sub region that represents this particular borrow.
- Relatedly, draw a distinction between lifetimes and scopes/regions of values.
- Explain why methods of the form
fn m(&'a mut self), where 'a is a lifetime parameter of the struct, is almost always not what’s needed.
- Talk a bit more and provide examples of how compiler is able to coerce longer lifetimes to shorter ones when possible (eg variance of immutable refs).
- Explain how lifetime parameter bounds (eg `b:'a) can’t actually enforce that some value outlives another. This has come up a few times on this forum.
- Explain and give examples of what it means for
&'a mut Tto be variant over 'a but invariant over T
- Show some examples of variance in play (eg rerurning a longer lived reference, such as 'static, from an otherwise generic lifetime using fn.
- Show examples where a struct should have multiple independent lifetime parameters vs being able to reuse one across fields. This is back to invariance.
- Show some examples of traits having a lifetime parameter, and explain the purpose.
- HRTB examples, such as expressing generic bounds for references
- Explain difference between mut ref moving and reborrowing, and ways to select one of them manually when need be
- Explain what the
T: 'abound means in
struct Foo<'a, T: 'a>and when/why it’s needed.