What's So Smart About Pointers Anyway?
Smart Pointers are a meaty subject in Rust. I’ve only scratched the surface. Boxes are useful when all you need is indirection. For example, to recursively define a linked list, you use a box to allocate data on the heap. In cases where a single value might have multiple owners, such as with graph data structures, the Reference-Counted smart pointer is available to keep track of the number of references to a value. Once the number of references reaches zero, the value can be dropped without leaving dangling references. And in situations where the compiler can’t guarantee your code follows Rust’s borrowing rules, but you can, the interior mutability pattern exists to shift enforcement to runtime so you can change the inner value of an immutable type as you see fit: