[][src]Struct refpool::Pool

pub struct Pool<A> { /* fields omitted */ }

A pool of preallocated memory sized to match type A.

In order to use it to allocate objects, pass it to PoolRef::new() or PoolRef::default().


let mut pool: Pool<usize> = Pool::new(1024);
let pool_ref = PoolRef::new(&mut pool, 31337);
assert_eq!(31337, *pool_ref);


impl<A> Pool<A>[src]

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

Construct a new pool with a given max size and return a handle to it.

Values constructed via the pool will be returned to the pool when dropped, up to max_size. When the pool is full, values will be dropped in the regular way.

If max_size is 0, meaning the pool can never hold any dropped values, this method will give you back a null handle without allocating a pool. You can still use this to construct PoolRef values, they'll just allocate in the old fashioned way without using a pool. It is therefore advisable to use a zero size pool as a null value instead of Option<Pool>, which eliminates the need for unwrapping the Option value.

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

Get the maximum size of the pool.

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

Get the current size of the pool.

pub fn is_full(&self) -> bool[src]

Test if the pool is currently full.

pub fn fill(&self)[src]

Fill the pool with empty allocations.

This operation will pre-allocate self.get_max_size() - self.get_pool_size() memory chunks, without initialisation, and put them in the pool.


let pool: Pool<usize> = Pool::new(1024);
assert_eq!(0, pool.get_pool_size());
assert_eq!(1024, pool.get_pool_size());

pub fn filled(self) -> Self[src]

Fill the pool and return it.

This is a convenience function that calls fill() on the pool, so that you can construct a pool with a one liner:

let pool: Pool<u64> = Pool::new(1024).filled();

This is functionally equivalent to, but terser than:

let mut pool: Pool<u64> = Pool::new(1024);

pub fn cast<B>(&self) -> Pool<B>[src]

Convert a pool handle for type A into a handle for type B.

The types A and B must have the same size and alignment, as per std::mem::size_of and std::mem::align_of, or this method will panic.

This lets you use the same pool to construct values of different types, as long as they are of the same size and alignment, so they can reuse each others' memory allocations.


let u64_pool: Pool<u64> = Pool::new(1024);
let u64_number = PoolRef::new(&u64_pool, 1337);

let i64_pool: Pool<i64> = u64_pool.cast();
let i64_number = PoolRef::new(&i64_pool, -1337);

Trait Implementations

impl<A> Clone for Pool<A>[src]

impl<A> Debug for Pool<A>[src]

fn fmt(&self, f: &mut Formatter) -> Result<(), Error>[src]

Debug implementation for Pool.


let mut pool: Pool<usize> = Pool::new(256);
assert!(format!("{:?}", pool).starts_with("Pool[0/256]:0x"));
assert!(format!("{:?}", pool).starts_with("Pool[256/256]:0x"));

impl<A> Drop for Pool<A>[src]

Auto Trait Implementations

impl<A> RefUnwindSafe for Pool<A> where
    A: RefUnwindSafe

impl<A> !Send for Pool<A>

impl<A> !Sync for Pool<A>

impl<A> Unpin for Pool<A>

impl<A> UnwindSafe for Pool<A> where
    A: RefUnwindSafe

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

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

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.