We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Ownership III: Lifetimes, Explicitly
RustReturn 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.
Your learning sequence
- 1 Every reference has a lifetime Read
- 2 A lifetime is a constraint, not a duration Read
- 3 Not solved yet. Borrow it or own it: your first lifetime decision Practice · Easy
- 4 How to read a lifetime error Read
- 5 The three elision rules, precisely Read
- 6 Not solved yet. Use lifetime elision for borrowed string results Practice · Easy
- 7 When elision fails: reading E0106 Read
-
8
Not solved yet.
longest: writing your first'aPractice · Medium - 9 Not solved yet. Two inputs, one output lifetime Practice · Medium
- 10 Returning references safely: E0515 Read
- 11 Structs that hold references Read
-
12
Not solved yet.
Zero-copy tokenizer:
Parser<'a>Practice · Hard - 13 Choose the right lifetime for a borrowed view Read
- 14 Make borrowed return types visible with lifetime syntax Read
-
15
Not solved yet.
Make the lint happy:
'_in return paths Practice · Easy -
16
'static: references and type bounds Read - 17 Not solved yet. Store owned and borrowed closures in registries Practice · Hard
- 18 Trait objects have lifetimes too Read
- 19 Helping closures infer reference lifetimes Read
- 20 Temporary scopes: E0716 and what edition 2024 changed Read
-
21
Outlives bounds:
'a: 'b,T: 'a, and implied bounds Read - 22 Not solved yet. Generics, traits and lifetimes in one signature Practice · Medium
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
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");
}