[−][src]Struct dynamic_pool::DynamicPool
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]
initial_capacity: usize,
maximum_capacity: usize,
create: F
) -> DynamicPool<T>
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]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[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,
T: Send,
impl<T> Sync for DynamicPool<T> where
T: Send,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,