typeover
rust curriculum

Curriculum Ownership & borrowing Lifetime intuition exercise 4 · fill-word

Lifetime intuition

r is declared in the outer scope, then assigned inside a block. Fill the keyword that gives s its OWN outer-scope binding so the borrow &s is valid when r is printed.

TypeScript reference
Fill the blanks →

About this theme

Lifetimes are not a separate runtime feature; they describe how long references are valid. This theme avoids advanced annotation syntax at first and focuses on why Rust rejects dangling references. Planned exercises: 1. choose the value that lives long enough. 2. recognise a dangling reference. 3. choose owned return instead of borrowed return. 4. fill a scope change that extends an owner. 5. fill a returned String. 6. write a function that returns one of two borrowed inputs with an explicit lifetime. 7. write code that avoids returning a local reference. 8. translate a TS closure over local data. 9. fix a lifetime error by changing ownership rather than adding random annotations.