[][src]Struct dynamic_pool::DynamicPool

pub struct DynamicPool<T: DynamicReset> { /* fields omitted */ }

a lock-free, thread-safe, dynamically-sized object pool.

this pool begins with an initial capacity and will continue creating new objects on request when none are available. pooled objects are returned to the pool on destruction (with an extra provision to optionally "reset" the state of an object for re-use).

if, during an attempted return, a pool already has maximum_capacity objects in the pool, the pool will throw away that object.

Methods

impl<T: DynamicReset> DynamicPool<T>[src]

pub fn new<F: Fn() -> T + Sync + Send + 'static>(
    initial_capacity: usize,
    maximum_capacity: usize,
    create: F
) -> DynamicPool<T>
[src]

creates a new DynamicPool<T>. this pool will create initial_capacity objects, and retain up to maximum_capacity objects.

panics.

panics if initial_capacity > maximum_capacity.

pub fn take(&self) -> DynamicPoolItem<T>[src]

takes an item from the pool, creating one if none are available.

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

attempts to take an item from the pool, returning none if none is available. will never allocate.

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

returns the number of free objects in the pool.

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

returns the number of objects currently in use. does not include objects that have been detached.

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

Trait Implementations

impl<T: DynamicReset> Clone for DynamicPool<T>[src]

impl<T: Debug + DynamicReset> Debug for DynamicPool<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for DynamicPool<T>

impl<T> Send for DynamicPool<T> where
    T: Send

impl<T> Sync for DynamicPool<T> where
    T: Send

impl<T> Unpin for DynamicPool<T>

impl<T> !UnwindSafe for DynamicPool<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.