Lifetime — reference validity scope.
Basic annotation:
1fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {2 if x.len() > y.len() { x } else { y }3}
Struct lifetimes:
1struct Excerpt<'a> {2 part: &'a str,3}45impl<'a> Excerpt<'a> {6 fn level(&self) -> i32 { 3 }7}
Lifetime elision:
1fn first_word<'a>(s: &'a str) -> &'a str { &s[..1] }
Key: Annotate when compiler can't infer.