pub unsafe trait SlabStore {
type Item;
// Required methods
fn alloc(&self, value: Self::Item) -> Slot<Self::Item>;
unsafe fn free(&self, slot: Slot<Self::Item>);
unsafe fn take(&self, slot: Slot<Self::Item>) -> Self::Item;
unsafe fn free_ptr(&self, ptr: *mut SlotCell<Self::Item>);
}Expand description
Base trait for slab storage — allocation, deallocation, and value extraction.
§Allocation
alloc always returns a valid slot:
- Unbounded slabs grow as needed — allocation never fails.
- Bounded slabs panic if capacity is exceeded. This is intentional: running out of pre-allocated capacity is a capacity planning error, equivalent to OOM. The system should crash loudly rather than silently drop work.
For fallible allocation on bounded slabs, use BoundedStore::try_alloc.
§Safety
Implementors must uphold:
freemust drop the value and return the slot to the freelist.takemust move the value out and return the slot to the freelist.- The slot must have been allocated from
self.
Required Associated Types§
Required Methods§
Sourcefn alloc(&self, value: Self::Item) -> Slot<Self::Item>
fn alloc(&self, value: Self::Item) -> Slot<Self::Item>
Allocates a slot with the given value.
§Panics
Panics if the store is at capacity (bounded slabs only). This is a capacity planning error — size your slabs for peak load.
Sourceunsafe fn free(&self, slot: Slot<Self::Item>)
unsafe fn free(&self, slot: Slot<Self::Item>)
Drops the value and returns the slot to the freelist.
§Safety
slotmust have been allocated from this store.- No references to the slot’s value may exist.