A smart pointer behaves like a pointer but does more than hold a memory address. In Rust, smart pointers offer safer, feature-rich alternatives to raw pointers, which are unsafe to use. They often wrap a raw pointer and add rules or capabilities for working with the data it points to. section 6.2.2
Choose a type for the capability you need:
- Box<T> is a programmer-facing pointer type built on lower-level pointer machinery. section 6.2.3
- Rc<T> and Arc<T> support shared access. For deeply interlinked data, Weak pointers allow access without increasing the reference count, helping prevent cycles. section 6.2.3
- Cell<T> and RefCell<T> provide interior mutability. A combination such as Rc<RefCell<T>> trades runtime cost for the flexibility of mutation alongside shared ownership. section 6.2.2
Compare a reference and a box
Put an array behind a reference, then put another behind a Box<[u8]>. Print each value’s location, size, and pointed-to address. In the illustrated run, the reference occupies 8 bytes and the box occupies 16 bytes: pointer-like values need not have the same layout. Added capabilities can cost space and runtime work. section 6.2 section 6.5
These types are extensible: lower-level components in Rust’s core and allocation modules can serve as starting points for a new smart pointer. Building a safe one in full requires further Rust internals. section 6.2.3




