LocalPool

Struct LocalPool 

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

A struct representing an object pool for local thread, it cannot be moved between threads.

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

Implementations§

Source§

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

Source

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

Creates a new LocalPool 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) -> Rc<Self>

Wraps the pool allocator with an 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) -> RefLocalGuard<'_, 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: Rc<Self>) -> RcLocalGuard<P, T>

Gets an object from the pool that holds an rc 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 LocalPool<P, T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

impl<P, T> !RefUnwindSafe for LocalPool<P, T>

§

impl<P, T> !Send for LocalPool<P, T>

§

impl<P, T> !Sync for LocalPool<P, T>

§

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

§

impl<P, T> UnwindSafe for LocalPool<P, T>
where P: UnwindSafe, T: 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.