[][src]Struct lazy_async_pool::Pool

pub struct Pool<T: Send + 'static, F: Fn() -> U, U: Future<Output = Result<T, E>> + Unpin, E>(_);

Lazy Asyncronous Object Pool

Implementations

impl<T, F, U, E> Pool<T, F, U, E> where
    T: Send,
    F: Fn() -> U,
    U: Future<Output = Result<T, E>> + Unpin
[src]

pub fn new(cap: usize, gen: F) -> Self[src]

Generates a new pool.

Arguments

  • cap - Maximum number of objects to generate.
    • Use 0 to make it unbounded.
    • The timeout feature can cause it to go past this limit, but extra resources will be dropped when released.

pub async fn get(self) -> Result<PoolGuard<T, F, U, E>, E>[src]

Obtain an item from the pool. If the pool is exhausted and not at capacity, generates a new item. If the pool is exhausted and at capacity, wait for a new item to be available.

pub fn len(&self) -> usize[src]

Number of items available in the pool.

pub fn add(&self, item: T) -> Result<(), TrySendError<T>>[src]

Manually add a new item to the pool.

  • Does not count towards the cap.

Trait Implementations

impl<T, F, U, E> Clone for Pool<T, F, U, E> where
    T: Send,
    F: Fn() -> U,
    U: Future<Output = Result<T, E>> + Unpin
[src]

Auto Trait Implementations

impl<T, F, U, E> RefUnwindSafe for Pool<T, F, U, E> where
    F: RefUnwindSafe

impl<T, F, U, E> Send for Pool<T, F, U, E> where
    F: Send + Sync

impl<T, F, U, E> Sync for Pool<T, F, U, E> where
    F: Send + Sync

impl<T, F, U, E> Unpin for Pool<T, F, U, E>

impl<T, F, U, E> UnwindSafe for Pool<T, F, U, E> where
    F: RefUnwindSafe

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.