Skip to main content

ThreadLocalPool

Struct ThreadLocalPool 

Source
pub struct ThreadLocalPool<T> { /* private fields */ }
Expand description

A reusable-object pool for a single logical context.

Implementations§

Source§

impl<T> ThreadLocalPool<T>

Source

pub fn new(capacity: usize) -> Self

Create a pool with maximum capacity free objects.

Source

pub fn warm_up(&mut self, count: usize, factory: impl Fn() -> T)

Pre-populate the pool with objects produced by factory.

Source

pub fn acquire(&mut self, factory: impl FnOnce() -> T) -> T

Obtain an object from the pool, or allocate a new one via factory.

Source

pub fn release(&mut self, obj: T)

Return an object to the pool. If the pool is at capacity, the object is dropped.

Source

pub fn free_count(&self) -> usize

Number of objects currently in the free pool.

Source

pub fn capacity(&self) -> usize

Source

pub fn alloc_count(&self) -> u64

Source

pub fn recycle_count(&self) -> u64

Source

pub fn overflow_count(&self) -> u64

Source

pub fn is_empty(&self) -> bool

Source

pub fn is_full(&self) -> bool

Source

pub fn drain(&mut self) -> Vec<T>

Drain all free objects (e.g. at shutdown).

Auto Trait Implementations§

§

impl<T> Freeze for ThreadLocalPool<T>

§

impl<T> RefUnwindSafe for ThreadLocalPool<T>
where T: RefUnwindSafe,

§

impl<T> Send for ThreadLocalPool<T>
where T: Send,

§

impl<T> Sync for ThreadLocalPool<T>
where T: Sync,

§

impl<T> Unpin for ThreadLocalPool<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ThreadLocalPool<T>

§

impl<T> UnwindSafe for ThreadLocalPool<T>
where 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> 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.