pub struct Pool<A, S: ?Sized = dyn Storage<Slot = Gc<A>>, F = ()> { /* private fields */ }Expand description
An arena allocator for Active simulation objects that performs automatic garbage collection on terminated and unreferenced instances.
This pool manages a Storage backend and a reclaim list of memory
slots that are ready to be reused.
§Safety Notes
Rearranging the fields here can lead to undefined behavior upon dropping of
the pool. Specifically, dropping storage before reclaim will invalidate
the slots contained in reclaim, leading to undefined behavior when
reclaim is dropped later.
Implementations§
Source§impl<A> Pool<A>
impl<A> Pool<A>
Sourcepub fn fixed<const N: usize>() -> Pool<A, Array<Gc<A>, N>>
pub fn fixed<const N: usize>() -> Pool<A, Array<Gc<A>, N>>
Creates a pool with a fixed-size backing store.
This pool is suitable for no_std + no_alloc environments. It will
panic if an allocation is attempted when the pool is full.
Source§impl<A, S: ?Sized + Storage<Slot = Gc<A>>, F> Pool<A, S, F>
impl<A, S: ?Sized + Storage<Slot = Gc<A>>, F> Pool<A, S, F>
Sourcepub fn try_alloc<'a, 'p, B>(
self: &'a Pin<&mut Self>,
value: B,
) -> Result<Pin<&'a mut Lease<'a, Gc<A>>>, InsufficientSpace<B>>where
F: Cons<B, Lease<'p, A>>,
A: 'p,
pub fn try_alloc<'a, 'p, B>(
self: &'a Pin<&mut Self>,
value: B,
) -> Result<Pin<&'a mut Lease<'a, Gc<A>>>, InsufficientSpace<B>>where
F: Cons<B, Lease<'p, A>>,
A: 'p,
Attempts to allocate a new, Active object.
This method first tries to recycle a slot from the reclaim list. If the list is empty, it requests a new slot from the backing store.
This function is panic-safe. If the constructor function cons panics,
the slot (whether recycled or newly allocated) is safely returned to
the reclaim list, preventing memory leaks.
Returns a Result containing the pinned, allocated object, or the
original value if allocation fails (e.g., the backing store is full).
Trait Implementations§
impl<'pin, A, S: ?Sized, F> Unpin for Pool<A, S, F>where
PinnedFieldsOf<__Pool<'pin, A, S, F>>: Unpin,
Auto Trait Implementations§
impl<A, S = dyn Storage<Slot = Gc<A>>, F = ()> !Freeze for Pool<A, S, F>
impl<A, S = dyn Storage<Slot = Gc<A>>, F = ()> !RefUnwindSafe for Pool<A, S, F>
impl<A, S = dyn Storage<Slot = Gc<A>>, F = ()> !Send for Pool<A, S, F>
impl<A, S = dyn Storage<Slot = Gc<A>>, F = ()> !Sync for Pool<A, S, F>
impl<A, S = dyn Storage<Slot = Gc<A>>, F = ()> !UnwindSafe for Pool<A, S, F>
impl<A, S, F> UnsafeUnpin for Pool<A, S, F>
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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