Expand description
A pool of reusable objects that can be used to avoid allocation. *
Implementations
sourceimpl<A> Pool<A> where
A: Default + Clone,
impl<A> Pool<A> where
A: Default + Clone,
sourcepub fn new(allocator: Box<dyn Fn() + 'static, Global>) -> Pool<A>
pub fn new(allocator: Box<dyn Fn() + 'static, Global>) -> Pool<A>
@param allocator A fn that creates a new object.
sourcepub fn take(&mut self) -> Option<A>
pub fn take(&mut self) -> Option<A>
Take an object from the pool. If the pool is empty, a new object will be allocated.
You should later release the object back into the pool by calling put()
.
sourcepub fn put(&mut self, object: A)
pub fn put(&mut self, object: A)
Put an object into the pool. This should be called to release objects previously claimed with
take()
. Can also be called to pre-allocate the pool with new objects.
sourcepub fn set_size(&mut self, size: usize) -> &Pool<A>
pub fn set_size(&mut self, size: usize) -> &Pool<A>
Resizes the pool. If the given size is larger than the current number of pooled objects, new objects are allocated to expand the pool. Otherwise, objects are trimmed out of the pool.
@returns This instance, for chaining.
sourcepub fn set_capacity(&mut self, capacity: usize) -> &Pool<A>
pub fn set_capacity(&mut self, capacity: usize) -> &Pool<A>
Sets the maximum capacity of the pool. By default, the pool can grow to any size.
@returns This instance, for chaining.
Auto Trait Implementations
impl<A> !RefUnwindSafe for Pool<A>
impl<A> !Send for Pool<A>
impl<A> !Sync for Pool<A>
impl<A> Unpin for Pool<A> where
A: Unpin,
impl<A> !UnwindSafe for Pool<A>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<'a, T, C, M> Inspect<'a, C, &'a C, M> for T
impl<'a, T, C, M> Inspect<'a, C, &'a C, M> for T
impl<'a, T, C, M> Inspect<'a, C, &'a mut C, M> for T
impl<'a, T, C, M> Inspect<'a, C, &'a mut C, M> for T
impl<Fr, To> IntoColor<To> for Fr where
To: FromColor<Fr>,
impl<Fr, To> IntoColor<To> for Fr where
To: FromColor<Fr>,
fn into_color(self) -> To
fn into_color(self) -> To
Convert into color
impl<T> Pointable for T
impl<T> Pointable for T
impl<T> SetParameter for T
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
Sets value
as a parameter of self
.