[][src]Struct deadpool::unmanaged::Pool

pub struct Pool<T> { /* fields omitted */ }

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

impl<T> Pool<T>[src]

pub fn new(max_size: usize) -> Self[src]

Create a new empty pool with the given max_size.

pub async fn get<'_>(&'_ self) -> Object<T>[src]

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

pub fn try_get(&self) -> Option<Object<T>>[src]

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

pub async fn add<'_>(&'_ self, obj: T)[src]

Add object to pool. If the size has already reached max_size this function blocks until the object can be added to the pool.

pub fn try_add(&self, obj: T) -> Result<(), T>[src]

Try to add a pool to the object. If the size has already reached max_size the object is returned as Err<T>.

pub async fn remove<'_>(&'_ self) -> T[src]

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

This example is not tested
Object::take(pool.get().await)

pub fn try_remove(&self) -> Option<T>[src]

Try to remove an object from the pool. This is a shortcut for

This example is not tested
if let Some(obj) = self.try_get() {
    Some(Object::take(obj))
} else {
    None
}

pub fn status(&self) -> Status[src]

Retrieve status of the pool

Trait Implementations

impl<T> Clone for Pool<T>[src]

impl<T, I> From<I> for Pool<T> where
    I: IntoIterator<Item = T>,
    <I as IntoIterator>::IntoIter: ExactSizeIterator
[src]

fn from(iter: I) -> Pool<T>[src]

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

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.