Struct wasserglas::Pool[][src]

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

A thread safe object pool whose objects get automatically reattached upon drop.

Implementations

impl<T> Pool<T>[src]

pub fn associate(&self, object: T) -> Result<Reattach<'_, T>, T>[src]

Associates an object with the pool without immediately pushing into it, but returns the object wrapped in a Reattach so that it gets pushed into the pool once it goes out of scope.

Returns the object in error position if the pool is full.

pub fn apply<F>(&self, f: F) where
    F: Fn(&mut T), 
[src]

Apply a function to all objects in the pool. If the function is to be applied to all functions in the pool, the caller should ensure that the pool is not currently used in a parallel context.

pub fn try_apply<E, F>(&self, f: F) -> Result<(), E> where
    F: Fn(&mut T) -> Result<(), E>, 
[src]

Apply a fallible function to all objects in the pool. If the function is to be applied to all functions in the pool, the caller should ensure that the pool is not currently used in a parallel context.

pub fn associate_with<F>(&self, f: F) -> Option<Reattach<'_, T>> where
    F: Fn() -> T, 
[src]

Constructs an object from a closure and associates it with the pool without immediately pushing into it, but returns the object immediately wrapped in a Reattach so that it gets pushed into the pool once it goes out of scope.

Use this method if construction of the object should be dynamic (or is expensive) and should only be performed if the pool has space left.

Returns None if the pool was at capacity and no object was constructed.

pub fn try_associate_with<E, F>(
    &self,
    f: F
) -> Result<Option<Reattach<'_, T>>, E> where
    F: Fn() -> Result<T, E>, 
[src]

Constructs an object from a fallible closure and associates it with the pool without immediately pushing into it, but returns the object immediately wrapped in a Reattach so that it gets pushed into the pool once it goes out of scope.

Use this method if construction of the object can fail, should be dynamic (oriis expensive) and should only be performed if the pool has space left.

Returns E in error position if construction fails, and None in okay position if the pool was at capacity and no object was constructed.

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

Returns the maximum capacity of the object pool.

pub fn into_inner(self) -> VecDeque<T>[src]

Consume the pool and return the inner VecDeque with all objects.

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

Returns the length of the pool, i.e. the number of objects currently associated with it. Note that this means all objects associated with the thread pool, both immediately available to be pulled from the pool and currently in flight.

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

Returns the number of objects available right now in the pool for pulling.

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

Returns the number of objects currently in flight, which is the the difference between all objects associated with the threadpool and those currently in the pool.

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

Creates a new fixed size object pool of max_capacity.

Panics if max_capacity < 1

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

Push an object into the pool. Returns the object in error position if the pool was at max capacity.

pub fn push_with<F>(&self, f: F) -> bool where
    F: Fn() -> T, 
[src]

Constructs an object T using a closure if the object pool is not at capacity and pushes it into the pool. Returns true if the object was sucessfully pushed into the pool, and false otherwise.

This method is useful if the object is supposed to be constructed dynamically (if for example construction of the object is expensive).

pub fn try_push_with<F, E>(&self, f: F) -> Result<bool, E> where
    F: Fn() -> Result<T, E>, 
[src]

Constructs an object T using a fallible closure if the object pool is not at capacity, and pushes it into the pool. Returns true in okay position if the push was successful, false if it failed, and E in error position if constructing the object failed.

This method is useful if the object is supposed to be constructed dynamically (if for example construction of the object is expensive) or if it can fail.

pub fn pull(&self) -> Reattach<'_, T>[src]

Pull an object from the pool. Blocks the current thread until an object becomes available to be pulled.

pub fn pull_once(&self) -> Option<Reattach<'_, T>>[src]

Pull an object from the pool. Attempts exactly one pull and returns None if the pool was empty.

pub fn pull_or(&self, object: T) -> Result<Reattach<'_, T>, T>[src]

Pull an object from the pool or associate the supplied object with the pool if the pool has no available objects and is not yet at capacity. If the pool is at capacity the current thread will be blocked until an object becomes available to be pulled.

pub fn pull_or_once(&self, object: T) -> Result<Option<Reattach<'_, T>>, T>[src]

Pull an object from the pool or associate the supplied object with the pool if the pool has no available objects an dis not yet at capacity.

Attempts exactly one pull and returns None if the pool was empty.

pub fn pull_or_else<F>(&self, f: F) -> Reattach<'_, T> where
    F: Fn() -> T, 
[src]

Pull an object from the pool or construct an object with the supplied closure and associate it with the pool if the pool has no available objects and is not yet at capacity. If the pool is at capacity the current thread will be blocked until an object becomes available to be pulled.

pub fn pull_or_else_once<F>(&self, f: F) -> Option<Reattach<'_, T>> where
    F: Fn() -> T, 
[src]

Pull an object from the pool or construct an object with the supplied closure and associate it with the pool if the pool has no available objects and is not yet at capacity.

Attempts exactly one pull and returns None if the pool was empty.

pub fn try_pull_or_else<E, F>(&self, f: F) -> Result<Reattach<'_, T>, E> where
    F: Fn() -> Result<T, E>, 
[src]

Pull an object from the pool or construct an object with the supplied fallible closure and associate it with the pool if the pool has no available objects and is not yet at capacity. If the pool is at capacity the current thread will be blocked until an object becomes available to be pulled.

Returns the closure’s error if object construction failed.

pub fn try_pull_or_else_once<E, F>(
    &self,
    f: F
) -> Result<Option<Reattach<'_, T>>, E> where
    F: Fn() -> Result<T, E>, 
[src]

Pull an object from the pool or construct an object with the supplied fallible closure and associate it with the pool if the pool has no available objects and is not yet at capacity.

Returns the closure’s error if object construction failed.

Attempts exactly one pull and returns None if the pool was empty.

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> where
    T: Unpin

impl<T> UnwindSafe for Pool<T> where
    T: UnwindSafe

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

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

Performs the conversion.

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.

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

Performs the conversion.