Next, we'll take a look at a few generic types by which we can control how the memory allocation in the heap is done. The types are as follows:
- Box<T>: This is the simplest form of heap allocation. The box owns the value inside it, and can thus be used for holding values inside structs or for returning them from functions.
- Cell<T>: This gives us internal mutability for types that implement the Copy trait. In other words, we gain the possibility to get multiple mutable references to something.
- RefCell<T>: This gives us internal mutability for types, without requiring the Copy trait. Uses runtime locking for safety.
- Rc<T>: This is for reference counting. It increments a counter whenever somebody takes a new reference, decrements ...