Struct Pool

Source
pub struct Pool<P: PoolAllocator<T>, T> { /* private fields */ }
Expand description

A struct representing an object pool.

This struct uses an allocator to create and manage objects, and stores them in an ArrayQueue.

Implementations§

Source§

impl<P: PoolAllocator<T>, T> Pool<P, T>

Source

pub fn new_prefilled(pool_size: usize, allocator: P) -> Self

Creates a new Pool with a given size and allocator.

This method immediately fills the pool with new objects created by the allocator.

Source

pub fn new(pool_size: usize, allocator: P) -> Self

Creates a new Object Pool with a given size and allocator.

Unlike Self::new_prefilled, this method does not immediately fill the pool with objects.

Source

pub fn to_rc(self) -> Arc<Self>

Wraps the pool allocator with an atomic reference counter, enabling the use of Self::get_rc to obtain pool-allocated objects that rely on reference counted references instead of borrowed references.

Source

pub fn get(&self) -> RefGuard<'_, P, T>

Gets an object from the pool.

If the pool is empty, a new object is created using the allocator.

Source

pub fn get_rc(self: Arc<Self>) -> RcGuard<P, T>

Gets an object from the pool that holds an arc reference to the owning pool. Allocated objects are not as efficient as those allocated by Self::get method but they are easier to move as they are not limited by allocator lifetime directly.

If the pool is empty, a new object is created using the allocator.

Trait Implementations§

Source§

impl<P: Debug + PoolAllocator<T>, T: Debug> Debug for Pool<P, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: PoolAllocator<T>, T: Send> Send for Pool<P, T>

Auto Trait Implementations§

§

impl<P, T> !Freeze for Pool<P, T>

§

impl<P, T> RefUnwindSafe for Pool<P, T>
where P: RefUnwindSafe,

§

impl<P, T> Sync for Pool<P, T>
where P: Sync, T: Send,

§

impl<P, T> Unpin for Pool<P, T>
where P: Unpin,

§

impl<P, T> UnwindSafe for Pool<P, T>
where P: UnwindSafe,

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