Isn't rust too difficult to be widely adopted?

Some ideas off the top of my head:

  1. 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.
  2. Relatedly, draw a distinction between lifetimes and scopes/regions of values.
  3. 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.
  4. 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).
  5. 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.
  6. Explain and give examples of what it means for &'a mut T to be variant over 'a but invariant over T
  7. Show some examples of variance in play (eg rerurning a longer lived reference, such as 'static, from an otherwise generic lifetime using fn.
  8. Show examples where a struct should have multiple independent lifetime parameters vs being able to reuse one across fields. This is back to invariance.
  9. Show some examples of traits having a lifetime parameter, and explain the purpose.
  10. HRTB examples, such as expressing generic bounds for references
  11. Explain difference between mut ref moving and reborrowing, and ways to select one of them manually when need be
  12. Explain what the T: 'a bound means in struct Foo<'a, T: 'a> and when/why it's needed.
15 Likes