pub struct ObjectSlab {
pub free_list: Vec<usize>,
/* private fields */
}Expand description
A deterministic slab allocator for type-erased objects.
Replaces the old mark-sweep GcHeap. Objects are reference-counted
and freed automatically when no references remain. The slab provides
stable indexed access and deterministic slot reuse.
Fields§
§free_list: Vec<usize>Free-list for slot reuse (LIFO for determinism).
Implementations§
Source§impl ObjectSlab
impl ObjectSlab
Sourcepub fn alloc<T: Any + 'static>(&mut self, value: T) -> SlabRef
pub fn alloc<T: Any + 'static>(&mut self, value: T) -> SlabRef
Allocate a value in the slab, returning a handle.
Reuses a freed slot if available (LIFO), otherwise extends the slab.
Sourcepub fn get<T: Any + 'static>(&self, slab_ref: SlabRef) -> Option<&T>
pub fn get<T: Any + 'static>(&self, slab_ref: SlabRef) -> Option<&T>
Read a reference to the value behind slab_ref, downcasting to T.
Returns None if the slot is empty or the type does not match.
Sourcepub fn get_mut<T: Any + 'static>(
&self,
slab_ref: SlabRef,
) -> Option<RefMut<'_, Box<dyn Any>>>
pub fn get_mut<T: Any + 'static>( &self, slab_ref: SlabRef, ) -> Option<RefMut<'_, Box<dyn Any>>>
Get a mutable reference to the value behind slab_ref.
Sourcepub fn live_count(&self) -> usize
pub fn live_count(&self) -> usize
Number of live (non-None) objects in the slab.
Sourcepub fn alloc_count(&self) -> usize
pub fn alloc_count(&self) -> usize
Total allocations performed since creation.
Sourcepub fn free(&mut self, slab_ref: SlabRef)
pub fn free(&mut self, slab_ref: SlabRef)
Explicitly free a slot (return to free-list).
This is optional — objects are also freed when their Rc drops to zero. Use this for explicit lifecycle management.
Sourcepub fn collect_noop(&self)
pub fn collect_noop(&self)
No-op collect for backward compatibility with GC API.
The object slab uses reference counting; there is nothing to collect.
This method exists so that gc_collect builtins don’t need to be
removed from user code immediately.
Trait Implementations§
Source§impl Debug for ObjectSlab
impl Debug for ObjectSlab
Auto Trait Implementations§
impl Freeze for ObjectSlab
impl !RefUnwindSafe for ObjectSlab
impl !Send for ObjectSlab
impl !Sync for ObjectSlab
impl Unpin for ObjectSlab
impl UnsafeUnpin for ObjectSlab
impl !UnwindSafe for ObjectSlab
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more