Struct opool::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> !RefUnwindSafe for Pool<P, T>

§

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, T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.