[][src]Struct idalloc::Slab

pub struct Slab<I> where
    I: Id
{ /* fields omitted */ }

A slab-based id allocator which can deal with automatic reclamation as ids are freed.

Examples

use idalloc::Slab;

let mut alloc = Slab::<u32>::new();

let mut alloc = Slab::<u32>::new();
assert_eq!(0, alloc.next());
assert_eq!(1, alloc.next());
alloc.free(0);
assert_eq!(0, alloc.next());
assert_eq!(2, alloc.next());
alloc.free(0);
alloc.free(0);
alloc.free(1);
assert_eq!(1, alloc.next());
assert_eq!(0, alloc.next());
assert_eq!(3, alloc.next());

Methods

impl<I> Slab<I> where
    I: Id
[src]

pub fn new() -> Self[src]

Construct a new slab allocator.

Examples

use idalloc::Slab;

let mut alloc = Slab::<u32>::new();

let mut alloc = Slab::<u32>::new();
assert_eq!(0, alloc.next());
assert_eq!(1, alloc.next());
alloc.free(0);
assert_eq!(0, alloc.next());

pub fn next(&mut self) -> I[src]

Allocate the next id.

Examples

let mut alloc = idalloc::Slab::<u32>::new();
assert_eq!(0u32, alloc.next());
assert_eq!(1u32, alloc.next());

pub fn free(&mut self, index: I) -> bool[src]

Free the specified id.

Examples

let mut alloc = idalloc::Slab::<u32>::new();
let id = alloc.next();
assert!(!alloc.free(id + 1));
assert!(alloc.free(id));
assert!(!alloc.free(id));

Trait Implementations

impl<I> Default for Slab<I> where
    I: Id
[src]

Auto Trait Implementations

impl<I> RefUnwindSafe for Slab<I> where
    I: RefUnwindSafe

impl<I> Send for Slab<I> where
    I: Send

impl<I> Sync for Slab<I> where
    I: Sync

impl<I> Unpin for Slab<I> where
    I: Unpin

impl<I> UnwindSafe for Slab<I> where
    I: UnwindSafe

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, 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.