Smart Pointers & Interior Mutability
Box, Rc, RefCell, Cow and Weak — what each one buys, what it costs, and the compile-time versus runtime borrow distinction that decides which one you actually need.
// lessons
- 01
Box<T> & Recursive Types
Give a recursive enum a known size.
- 02
Rc<T> & Shared Ownership
Share one allocation between several owners on one thread.
- 03
RefCell<T> & Runtime Borrowing
Move a borrow check from compile time to runtime — and accept the panic that buys.
- 04
Weak<T> & Reference Cycles
Build a parent/child graph that actually gets freed.
- 05
Cow<T> & Allocating Only When You Must
Return borrowed data on the common path, owned on the rare one.
- 06
Deref, DerefMut & Custom Pointers
Make your own wrapper behave like the thing it wraps.
Every exercise compiles and runs in the Forge sandbox — standard library only, no external crates.
