Struct lifeguard::Pool
[−]
[src]
pub struct Pool<T> where T: Recycleable {
// some fields omitted
}
A collection of values that can be reused without requiring new allocations.
Pool
issues each value wrapped in a smartpointer. When the smartpointer goes out of
scope, the wrapped value is automatically returned to the pool.
Methods
impl<T> Pool<T> where T: Recycleable
[src]
fn with_size(size: usize) -> Pool<T>
Creates a pool with size
elements of type T
allocated.
fn with_size_and_max(starting_size: usize, max_size: usize) -> Pool<T>
Creates a pool with size
elements of type T
allocated
and sets a maximum pool size of max_size
. Values being
added to the pool via Pool::attach
or being returned to
the pool upon dropping will instead be discarded if the pool
is full.
fn size(&self) -> usize
Returns the number of values remaining in the pool.
fn max_size(&self) -> usize
Returns the maximum number of values the pool can hold.
fn new(&self) -> Recycled<T>
Removes a value from the pool and returns it wrapped in a `Recycled smartpointer. If the pool is empty when the method is called, a new value will be allocated.
fn new_from<A>(&self, source: A) -> Recycled<T> where T: InitializeWith<A>
Removes a value from the pool, initializes it using the provided
source value, and returns it wrapped in a Recycled
smartpointer.
If the pool is empty when the method is called, a new value will be
allocated.
fn attach(&self, value: T) -> Recycled<T>
Associates the provided value with the pool by wrapping it in a
Recycled
smartpointer.
fn detached(&self) -> T
Removes a value from the pool and returns it without wrapping it in a smartpointer. When the value goes out of scope it will not be returned to the pool.
fn new_rc(&self) -> RcRecycled<T>
Removes a value from the pool and returns it wrapped in
an RcRecycled
smartpointer. If the pool is empty when the
method is called, a new value will be allocated.
fn new_rc_from<A>(&self, source: A) -> RcRecycled<T> where T: InitializeWith<A>
Removes a value from the pool, initializes it using the provided
source value, and returns it wrapped in an RcRecycled
smartpointer.
If the pool is empty when the method is called, a new value will be
allocated.
fn attach_rc(&self, value: T) -> RcRecycled<T>
Associates the provided value with the pool by wrapping it in an
RcRecycled
smartpointer.