Back to course

Deeper into Smart Pointers: Rc & RefCell

Rust for Systems & Web3 Security

Multiple Ownership

Sometimes a value needs multiple owners.

  1. Rc<T> (Reference Counting): Allows multiple owners. When the last owner is dropped, the data is freed. (Only for single-threaded use).
  2. RefCell<T>: Allows Interior Mutability. You can mutate data even when you have an immutable reference to the RefCell (checked at runtime).

In Web3, these are used for complex graph-like data structures or state management.