singularity

Chapter 15: Smart Pointers

Using Box to Point to Data on the Heap

Using Box to Store Data on the Heap

Enabling Recursive Types with Boxes

Treating Smart Pointers Like Regular References with Deref

Following the Pointer to the Value

Using Box Like a Reference

Defining Our Own Smart Pointer

Implementing the Deref Trait

Implicit Deref Coercions with Functions and Methods

How Deref Coercion Interacts with Mutability

Running Code on Cleanup with the Drop Trait

Rc, the Reference Counted Smart Pointer

Using Rc to Share Data

Cloning an Rc Increases the Reference Count

RefCell and the Interior Mutability Pattern

Enforcing Borrowing Rules at Runtime with RefCell

Interior Mutability: A Mutable Borrow to an Immutable Value

Allowing Multiple Owners of Mutable Data with Rc and RefCell

Reference Cycles Can Leak Memory

Creating a Reference Cycle

Preventing Reference Cycles Using Weak