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>
impl<T: Default + Send + 'static> GlobalPool<T>
Sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Create a new global pool retaining at most max_size objects.
Sourcepub fn get(&self) -> T
pub fn get(&self) -> T
Get an object from the pool, or construct a new one if the pool is empty.
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>where
LockFreeStack<T>: UnsafeUnpin,
impl<T> UnwindSafe for GlobalPool<T>where
LockFreeStack<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more