Step Into Labs

Step Into Rust · Lesson 8 · Robust Rust

Lifetimes

How long a borrow lives: lifetime parameters, structs that borrow, and zero-copy parsing.

Part of Step Into Rust. The full lesson, its missions and the real compiler and debugger are in the course. Try a free lesson first to see how it works.

A lifetime is the stretch of code where a reference is valid. The borrow checker makes sure no reference outlives the data it points to: the dangling pointers that cause use-after-free bugs in C simply don't compile.

In this lesson

Missions

  1. longest
  2. A struct that borrows
  3. Make it an Iterator
  4. Zero-copy binary parsing