Note that this is meant to be a common subset of useful types, not an exhaustive list.
Box<T>
, casually referred to as a 'box', provides the simplest form of heap allocation in Rust. Boxes provide ownership for this allocation, and drop their contents when they go out of scope. Boxes also ensure that they never allocate more thanisize::MAX
bytes.
Arc
: Atomically Reference-Counted pointer, which can be used in multithreaded environments to prolong the lifetime of some data until all the threads have finished using it.Barrier
: Ensures multiple threads will wait for each other to reach a point in the program, before continuing execution all together.Condvar
: Condition Variable, providing the ability to block a thread while waiting for an event to occur.mpsc
: Multi-producer, single-consumer queues (channels), used for message-based communication. Can provide a lightweight inter-thread synchronisation mechanism, at the cost of some extra memory.Mutex
: Mutual Exclusion mechanism, which ensures that at most one thread at a time is able to access some data.Once
: Used for thread-safe, one-time initialization of a global variable.RwLock
: Provides a mutual exclusion mechanism which allows multiple readers at the same time, while allowing only one writer at a time. In some cases, this can be more efficient than a mutex.
Cell
: A mutable memory location.Ref
: Wraps a borrowed reference to a value in aRefCell
box. A wrapper type for an immutably borrowed value from aRefCell<T>
.RefCell
: A mutable memory location with dynamically checked borrow rulesRefMut
: A wrapper type for a mutably borrowed value from aRefCell<T>
.UnsafeCell
: The core primitive for interior mutability in Rust.
Rc
A single-threaded reference-counting pointer.'Rc'
stands for'Reference Counted'
.Weak
Weak is a version ofRc
that holds a non-owning reference to the managed allocation. The allocation is accessed by calling upgrade on the Weak pointer, which returns anOption<Rc<T>>
.
// TODO: examples, if needed anywhere