Skip to main content

Pool

Struct Pool 

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

Source

pub fn new<S>(storage: S) -> Pool<A, S>

Creates a new pool given a backing store.

Source

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

pub fn dynamic() -> Pool<A, Arena<Gc<A>>>

Available on crate feature alloc only.

Creates a pool with a dynamically growing backing store.

Source

pub fn with_capacity(n: usize) -> Pool<A, Arena<Gc<A>>>

Available on crate feature alloc only.

Creates a dynamically growing pool with a specified initial capacity.

Source§

impl<A, S: Storage<Slot = Gc<A>>> Pool<A, S>

Source

pub fn with<'p, B, F>(self, cons: F) -> Pool<A, S, F>
where F: Fn(B) -> Lease<'p, A>, A: 'p,

Sets a new constructor function for the pool.

Source§

impl<A, S: ?Sized + Storage<Slot = Gc<A>>, F> Pool<A, S, F>

Source

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).

Source

pub fn alloc<'a, 'p, B>( self: &'a Pin<&mut Self>, value: B, ) -> Pin<&'a mut Lease<'a, Gc<A>>>
where F: Cons<B, Lease<'p, A>>, A: 'p,

Allocates a new, Active object, panicking if allocation fails.

This is a convenience wrapper around try_alloc that panics on allocation failure. This is often acceptable in simulations where the pool size is expected to be sufficient.

Source

pub fn len(&self) -> usize

Returns the total number of allocated slots.

Source

pub fn is_empty(&self) -> bool

Returns true if no slots have been allocated.

Trait Implementations§

Source§

impl<A, S: Storage<Slot = Gc<A>> + Default> Default for Pool<A, S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A, S: Storage<Slot = Gc<A>>> From<S> for Pool<A, S>

Source§

fn from(storage: S) -> Self

Converts to this type from the input type.
Source§

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>
where F: UnsafeUnpin, S: UnsafeUnpin + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more