pub struct ObjectPool<T> { /* private fields */ }Expand description
A thread-safe queue that allows concurrent access and is used for pooling items.
Implementations§
Source§impl<T> ObjectPool<T>
impl<T> ObjectPool<T>
Sourcepub fn new<A>(args: A, initial_size: usize, capacity: Option<usize>) -> Self
pub fn new<A>(args: A, initial_size: usize, capacity: Option<usize>) -> Self
Create an object pool consisting of initial_size object initialized using
AsPooled::create.
The argument capacity can be provided to place an upper bound on the number of
objects in the pool. If initial_size > capacity, the pool will be created with
excess items.
Sourcepub fn try_new<A>(
args: A,
initial_size: usize,
capacity: Option<usize>,
) -> Result<Self, T::Error>where
T: TryAsPooled<A>,
A: Clone,
pub fn try_new<A>(
args: A,
initial_size: usize,
capacity: Option<usize>,
) -> Result<Self, T::Error>where
T: TryAsPooled<A>,
A: Clone,
Create an object pool consisting of initial_size object initialized using
TryAsPooled::try_create.
The argument capacity can be provided to place an upper bound on the number of
objects in the pool. If initial_size > capacity, the pool will be created with
excess items.
Sourcepub fn try_get_ref<A>(&self, args: A) -> Result<PooledRef<'_, T>, T::Error>where
T: TryAsPooled<A>,
pub fn try_get_ref<A>(&self, args: A) -> Result<PooledRef<'_, T>, T::Error>where
T: TryAsPooled<A>,
Try to retrieve an object from the pool. If the pool is non-empty, then invoke
TryAsPooled::try_modify on the object with the given arguments. Otherwise, invoke
TryAsPooled::try_create to create a new object.
If try_modify fails, the potentially modified object will not be returned to the
queue and will instead be dropped.
Sourcepub fn get_ref<A>(&self, args: A) -> PooledRef<'_, T>where
T: AsPooled<A>,
pub fn get_ref<A>(&self, args: A) -> PooledRef<'_, T>where
T: AsPooled<A>,
Try to retrieve an object from the pool. If the pool is non-empty, then invoke
AsPooled::modify on the object with the given arguments. Otherwise, invoke
AsPooled::create to create a new object.
Unlike ObjectPool::try_get_ref, this interface should be infallible.
If modify panics, the potentially modified object will not be returned to the
queue and will instead be dropped.
Sourcepub fn try_get<A>(self: &Arc<Self>, args: A) -> Result<PooledArc<T>, T::Error>where
T: TryAsPooled<A>,
pub fn try_get<A>(self: &Arc<Self>, args: A) -> Result<PooledArc<T>, T::Error>where
T: TryAsPooled<A>,
Try to retrieve an object from the pool. If the pool is non-empty, then invoke
[TryAsPooled::modify] on the object with the given arguments. Otherwise, invoke
[TryAsPooled::create] to create a new object.
If try_modify fails, the potentially modified object will not be returned to the
queue and will instead be dropped.
Sourcepub fn get<A>(self: &Arc<Self>, args: A) -> PooledArc<T>where
T: AsPooled<A>,
pub fn get<A>(self: &Arc<Self>, args: A) -> PooledArc<T>where
T: AsPooled<A>,
Try to retrieve an object from the pool. If the pool is non-empty, then invoke
AsPooled::modify on the object with the given arguments. Otherwise, invoke
AsPooled::create to create a new object.
Unlike ObjectPool::try_get, this interface should be infallible.
If modify panics, the potentially modified object will not be returned to the
queue and will instead be dropped.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for ObjectPool<T>
impl<T> RefUnwindSafe for ObjectPool<T>
impl<T> Send for ObjectPool<T>where
T: Send,
impl<T> Sync for ObjectPool<T>where
T: Send,
impl<T> Unpin for ObjectPool<T>where
T: Unpin,
impl<T> UnsafeUnpin for ObjectPool<T>
impl<T> UnwindSafe for ObjectPool<T>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more