Step Into Labs

Step Into Rust · Lesson 11 · Sharing & Concurrency

Box, Rc and RefCell

Recursive types on the heap, shared ownership with reference counts, mutation behind shared references, and Weak to break cycles.

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 type that contains itself directly would be infinitely large. Putting the inner value behind a Box makes it one pointer:

In this lesson

Missions

  1. A tree of boxes
  2. Count the owners
  3. One log, two writers
  4. A parent you do not own