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

Create a new empty pool with the given max_size.

Create a new empty pool using the given configuration

Retrieve object from pool or wait for one to become available.

Retrieve object from the pool and do not wait if there is currently no object available and the maximum pool size has been reached.

Retrieve object using a different timeout config than the one configured.

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.

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.

Remove an object from the pool. This is a shortcut for

Object::take(pool.get()?.await)

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
}

Remove object using a different timeout config than the one configured. This is a shortcut for

Object::take(pool.timeout_get()?.await)

Close the pool

All current and future tasks waiting for objects return Err(PoolError::Closed) immediately.

Returns true if the pool has been closed

Retrieve status of the pool

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Create new pool from the given exact size iterator of objects.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.