Skip to main content

SlabStore

Trait SlabStore 

Source
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:

  • free must drop the value and return the slot to the freelist.
  • take must move the value out and return the slot to the freelist.
  • The slot must have been allocated from self.

Required Associated Types§

Source

type Item

The type stored in each slot.

Required Methods§

Source

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.

Source

unsafe fn free(&self, slot: Slot<Self::Item>)

Drops the value and returns the slot to the freelist.

§Safety
  • slot must have been allocated from this store.
  • No references to the slot’s value may exist.
Source

unsafe fn take(&self, slot: Slot<Self::Item>) -> Self::Item

Moves the value out and returns the slot to the freelist.

§Safety
  • slot must have been allocated from this store.
  • No references to the slot’s value may exist.
Source

unsafe fn free_ptr(&self, ptr: *mut SlotCell<Self::Item>)

Returns a slot to the freelist by raw pointer.

Does NOT drop the value — caller must have already dropped or moved it.

§Safety
  • ptr must point to a slot within this store.
  • The value must already be dropped or moved out.

Implementors§

Source§

impl<T> SlabStore for nexus_timer::store::BoundedSlab<T>

Source§

type Item = T

Source§

impl<T> SlabStore for nexus_timer::store::UnboundedSlab<T>

Source§

type Item = T