Skip to content
← All Rust tracks

Ownership III: Lifetimes, Explicitly

Rust

Return borrowed data safely. Start with lifetime elision, then add annotations where needed to describe relationships between inputs, outputs and stored references.

This track uses Rust. You can make it your practice mode to browse related content across the site.

8 exercises

14 articles

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Every reference has a lifetime Read
  2. 2 A lifetime is a constraint, not a duration Read
  3. 3 Not solved yet. Borrow it or own it: your first lifetime decision Practice · Easy
  4. 4 How to read a lifetime error Read
  5. 5 The three elision rules, precisely Read
  6. 6 Not solved yet. Use lifetime elision for borrowed string results Practice · Easy
  7. 7 When elision fails: reading E0106 Read
  8. 8 Not solved yet. longest: writing your first 'a Practice · Medium
  9. 9 Not solved yet. Two inputs, one output lifetime Practice · Medium
  10. 10 Returning references safely: E0515 Read
  11. 11 Structs that hold references Read
  12. 12 Not solved yet. Zero-copy tokenizer: Parser<'a> Practice · Hard
  13. 13 Choose the right lifetime for a borrowed view Read
  14. 14 Make borrowed return types visible with lifetime syntax Read
  15. 15 Not solved yet. Make the lint happy: '_ in return paths Practice · Easy
  16. 16 'static: references and type bounds Read
  17. 17 Not solved yet. Store owned and borrowed closures in registries Practice · Hard
  18. 18 Trait objects have lifetimes too Read
  19. 19 Helping closures infer reference lifetimes Read
  20. 20 Temporary scopes: E0716 and what edition 2024 changed Read
  21. 21 Outlives bounds: 'a: 'b, T: 'a, and implied bounds Read
  22. 22 Not solved yet. Generics, traits and lifetimes in one signature Practice · Medium

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

Why does an owned String satisfy the T: 'static bound?

Choose one answer to reveal the explanations. Answers are kept only while this page is open.

fn takes_static<T: 'static>(value: T) {
    drop(value);
}

fn main() {
    let mut text = String::from("owned");
    text.push('!');
    takes_static(text);
    println!("returned");
}
Question 1 of 4