pub struct GenerationalSlab<T, B: Allocator + FixedRange, G: GenerationInt = u32> { /* private fields */ }Expand description
Generational slab.
capacity slots, each holding either a live T or a free-list link.
Handles encode (slot_index, generation_at_allocate); access via
get / get_mut / remove
only succeeds when the slot’s current generation equals the handle’s.
§Thread safety
All mutation goes through &mut self. The slab is Send + Sync if T
and B are, but concurrent mutation requires external synchronization
(Mutex<GenerationalSlab<T, B>>).
Implementations§
Source§impl<T, B: Allocator + FixedRange> GenerationalSlab<T, B, u32>
impl<T, B: Allocator + FixedRange> GenerationalSlab<T, B, u32>
Sourcepub fn new(capacity: usize, backing: B) -> Result<Self, AllocError>
pub fn new(capacity: usize, backing: B) -> Result<Self, AllocError>
Construct with default u32 generation counter.
Source§impl<T, B: Allocator + FixedRange, G: GenerationInt> GenerationalSlab<T, B, G>
impl<T, B: Allocator + FixedRange, G: GenerationInt> GenerationalSlab<T, B, G>
Sourcepub fn with_generation(capacity: usize, backing: B) -> Result<Self, AllocError>
pub fn with_generation(capacity: usize, backing: B) -> Result<Self, AllocError>
Construct with an explicit generation-width parameter.
Use u64 for high-churn long-running servers where 2^32 reuses of
the same slot could realistically occur.
Sourcepub fn insert(&mut self, value: T) -> Result<Handle<T, G>, AllocError>
pub fn insert(&mut self, value: T) -> Result<Handle<T, G>, AllocError>
Insert a value and return its handle. Errors if the slab is full.
Sourcepub fn get(&self, handle: Handle<T, G>) -> Option<&T>
pub fn get(&self, handle: Handle<T, G>) -> Option<&T>
Borrow the value behind a handle, or None if stale / vacant.
Sourcepub fn get_mut(&mut self, handle: Handle<T, G>) -> Option<&mut T>
pub fn get_mut(&mut self, handle: Handle<T, G>) -> Option<&mut T>
Borrow mutably behind a handle, or None if stale / vacant.