Loading lesson…
Level 1 · Apprentice0 XP
How Rust knows a reference never outlives its data, and when you need to write 'a.
Step 1 / 6
ProblemA function returns a reference to a local variable. In C, the caller reads freed memory. Rust refuses to compile it.
← → step
Before this: Borrowing and references
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Write a struct Excerpt<'a> that borrows a sentence from a document, a function returning the first sentence of a &str, and then a version of the struct that owns a String. Compare which is easier to use in a Vec stored in a long-lived cache.