pub struct Pool<T> { /* private fields */ }
Expand description
A generic object and connection pool. This is the static version of the pool which does not include
This struct can be cloned and transferred across thread boundaries and uses reference counting for its internal state.
A pool of existing objects can be created from an existing collection of objects if it has a known exact size:
use deadpool::unmanaged::Pool;
let pool = Pool::from(vec![1, 2, 3]);
Implementations
sourceimpl<T> Pool<T>
impl<T> Pool<T>
sourcepub fn from_config(config: &PoolConfig) -> Self
pub fn from_config(config: &PoolConfig) -> Self
Create a new empty pool using the given configuration
sourcepub async fn get(&self) -> Result<Object<T>, PoolError>
pub async fn get(&self) -> Result<Object<T>, PoolError>
Retrieve object from pool or wait for one to become available.
sourcepub fn try_get(&self) -> Result<Object<T>, PoolError>
pub fn try_get(&self) -> Result<Object<T>, PoolError>
Retrieve object from the pool and do not wait if there is currently no object available and the maximum pool size has been reached.
sourcepub async fn timeout_get(
&self,
timeout: Option<Duration>
) -> Result<Object<T>, PoolError>
pub async fn timeout_get(
&self,
timeout: Option<Duration>
) -> Result<Object<T>, PoolError>
Retrieve object using a different timeout config than the one configured.
sourcepub async fn add(&self, obj: T) -> Result<(), (T, PoolError)>
pub async fn add(&self, obj: T) -> Result<(), (T, PoolError)>
Add object to pool. If the size
has already reached max_size
this function blocks until the object can be added to the pool.
If the pool has been closed a tuple containing the object and
the error is returned instead.
sourcepub fn try_add(&self, obj: T) -> Result<(), (T, PoolError)>
pub fn try_add(&self, obj: T) -> Result<(), (T, PoolError)>
Try to add a pool to the object. If the size
has already reached
max_size
or the pool has been closed a tuple containing the object
and the cause of the error is returned instead.
sourcepub async fn remove(&self) -> Result<T, PoolError>
pub async fn remove(&self) -> Result<T, PoolError>
Remove an object from the pool. This is a shortcut for
Object::take(pool.get()?.await)
sourcepub fn try_remove(&self) -> Result<T, PoolError>
pub fn try_remove(&self) -> Result<T, PoolError>
Try to remove an object from the pool. This is a shortcut for
if let Some(obj) = self.try_get() {
Some(Object::take(obj))
} else {
None
}
sourcepub async fn tiemout_remove(
&self,
timeout: Option<Duration>
) -> Result<T, PoolError>
pub async fn tiemout_remove(
&self,
timeout: Option<Duration>
) -> Result<T, PoolError>
Remove object using a different timeout config than the one configured. This is a shortcut for
Object::take(pool.timeout_get()?.await)
Trait Implementations
sourceimpl<T, I> From<I> for Pool<T> where
I: IntoIterator<Item = T>,
<I as IntoIterator>::IntoIter: ExactSizeIterator,
impl<T, I> From<I> for Pool<T> where
I: IntoIterator<Item = T>,
<I as IntoIterator>::IntoIter: ExactSizeIterator,
Auto Trait Implementations
impl<T> !RefUnwindSafe for Pool<T>
impl<T> Send for Pool<T> where
T: Send,
impl<T> Sync for Pool<T> where
T: Send,
impl<T> Unpin for Pool<T>
impl<T> !UnwindSafe for Pool<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more