1/6

Most signatures need no annotation, because three elision rules fill them in. Knowing them tells you exactly when you must write one yourself.

  1. Every elided input lifetime gets its own distinct parameter.
  2. If there is exactly one input lifetime, it is assigned to every elided output lifetime.
  3. If one of the inputs is &self or &mut self, its lifetime is assigned to every elided output lifetime.
fn first_word(s: &str) -> &str        // rule 2 — one input, no ambiguity
fn rest(&self) -> &str                // rule 3 — output borrows from self