Skip to main content

GlobalPool

Struct GlobalPool 

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

Global object pool for cross-thread sharing.

A lock-free stack of reusable objects shared by all threads; there is no per-thread caching layer. Self::get pops a pooled object or constructs a new one via T::default(); Self::put returns an object, dropping it when the pool already holds max_size objects.

Implementations§

Source§

impl<T: Default + Send + 'static> GlobalPool<T>

Source

pub fn new(max_size: usize) -> Self

Create a new global pool retaining at most max_size objects.

Source

pub fn get(&self) -> T

Get an object from the pool, or construct a new one if the pool is empty.

Source

pub fn put(&self, obj: T)

Return an object to the pool.

When the pool already holds max_size objects the object is dropped; this is the pool’s documented retention cap, not an error condition.

Source

pub fn clear(&self)

Clear all objects from the pool.

Auto Trait Implementations§

§

impl<T> !Freeze for GlobalPool<T>

§

impl<T> !RefUnwindSafe for GlobalPool<T>

§

impl<T> Send for GlobalPool<T>
where LockFreeStack<T>: Send,

§

impl<T> Sync for GlobalPool<T>
where LockFreeStack<T>: Sync,

§

impl<T> Unpin for GlobalPool<T>
where LockFreeStack<T>: Unpin,

§

impl<T> UnsafeUnpin for GlobalPool<T>

§

impl<T> UnwindSafe for GlobalPool<T>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.