pub struct Pool<T> { /* private fields */ }Expand description
A fixed-capacity slot pool handing out generation-checked handles.
Implementations§
Source§impl<T> Pool<T>
impl<T> Pool<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Reserve room for capacity objects. The pool never allocates again: it
hands out None when full rather than growing.
Sourcepub fn reserved_bytes(&self) -> u64
pub fn reserved_bytes(&self) -> u64
Bytes the pool reserved, occupied or not: what it costs the process whatever its occupancy, and so what it reports to a byte budget.
Sourcepub fn insert(&mut self, value: T) -> Option<PoolHandle>
pub fn insert(&mut self, value: T) -> Option<PoolHandle>
Place value in a free slot. None when the pool is full, which is the
caller’s cue to drop the request or widen the pool at setup.
Sourcepub fn remove(&mut self, handle: PoolHandle) -> Option<T>
pub fn remove(&mut self, handle: PoolHandle) -> Option<T>
Take the object back out, freeing its slot. None when the handle is
stale or already removed.
Sourcepub fn get(&self, handle: PoolHandle) -> Option<&T>
pub fn get(&self, handle: PoolHandle) -> Option<&T>
Borrow the object a handle names, if the handle is still live.
Sourcepub fn get_mut(&mut self, handle: PoolHandle) -> Option<&mut T>
pub fn get_mut(&mut self, handle: PoolHandle) -> Option<&mut T>
Mutably borrow the object a handle names, if it is still live.
Sourcepub fn get_at(&self, index: usize) -> Option<&T>
pub fn get_at(&self, index: usize) -> Option<&T>
Borrow whatever occupies a slot, by position rather than by handle.
For a caller that keeps its own tables alongside the pool and indexes them by slot: the position came from the pool, so re-checking a generation it never left would only cost a branch.
Sourcepub fn get_at_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_at_mut(&mut self, index: usize) -> Option<&mut T>
Mutably borrow whatever occupies a slot, by position.
Sourcepub fn handle_at(&self, index: usize) -> Option<PoolHandle>
pub fn handle_at(&self, index: usize) -> Option<PoolHandle>
The handle naming whatever occupies a slot, so a caller that walks
positions can hand one back out. None when the slot is vacant.
Sourcepub fn contains(&self, handle: PoolHandle) -> bool
pub fn contains(&self, handle: PoolHandle) -> bool
Whether a handle still names a live object.
Sourcepub fn iter(&self) -> impl Iterator<Item = (PoolHandle, &T)>
pub fn iter(&self) -> impl Iterator<Item = (PoolHandle, &T)>
Every live object with its handle, in slot order.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (PoolHandle, &mut T)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (PoolHandle, &mut T)>
Every live object with its handle, mutably, in slot order.