Struct deadpool::unmanaged::Pool

source ·
pub struct Pool<T> { /* private fields */ }
Expand description

Generic object and connection pool. This is the static version of the pool which doesn’t 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§

source§

impl<T> Pool<T>

source

pub fn new(max_size: usize) -> Self

Creates a new empty Pool with the given max_size.

source

pub fn from_config(config: &PoolConfig) -> Self

Create a new empty Pool using the given PoolConfig.

source

pub async fn get(&self) -> Result<Object<T>, PoolError>

Retrieves an Object from this Pool or waits for the one to become available.

§Errors

See PoolError for details.

source

pub fn try_get(&self) -> Result<Object<T>, PoolError>

Retrieves an Object from this Pool and doesn’t wait if there is currently no Object is available and the maximum Pool size has been reached.

§Errors

See PoolError for details.

source

pub async fn timeout_get( &self, timeout: Option<Duration>, ) -> Result<Object<T>, PoolError>

Retrieves an Object from this Pool using a different timeout than the configured one.

§Errors

See PoolError for details.

source

pub async fn add(&self, object: T) -> Result<(), (T, PoolError)>

Adds an object to this Pool.

If the Pool size has already reached its maximum, then this function blocks until the object can be added to the Pool.

§Errors

If the Pool has been closed a tuple containing the object and the PoolError is returned instead.

source

pub fn try_add(&self, object: T) -> Result<(), (T, PoolError)>

Tries to add an object to this Pool.

§Errors

If the Pool size has already reached its maximum, or the Pool has been closed, then a tuple containing the object and the PoolError is returned instead.

source

pub async fn remove(&self) -> Result<T, PoolError>

Removes an Object from this Pool.

source

pub fn try_remove(&self) -> Result<T, PoolError>

Tries to remove an Object from this Pool.

source

pub async fn timeout_remove( &self, timeout: Option<Duration>, ) -> Result<T, PoolError>

Removes an Object from this Pool using a different timeout than the configured one.

source

pub fn close(&self)

Closes this Pool.

All current and future tasks waiting for Objects will return PoolError::Closed immediately.

source

pub fn is_closed(&self) -> bool

Indicates whether this Pool has been closed.

source

pub fn status(&self) -> Status

Retrieves Status of this Pool.

Trait Implementations§

source§

impl<T> Clone for Pool<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Pool<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for Pool<T>

source§

fn default() -> Self

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

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

source§

fn from(iter: I) -> Self

Creates a new Pool from the given ExactSizeIterator of Objects.

Auto Trait Implementations§

§

impl<T> Freeze for Pool<T>

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.