[−][src]Struct idalloc::Slab
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]
I: Id,
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
Auto Trait Implementations
impl<I> RefUnwindSafe for Slab<I> where
I: RefUnwindSafe,
I: RefUnwindSafe,
impl<I> Send for Slab<I> where
I: Send,
I: Send,
impl<I> Sync for Slab<I> where
I: Sync,
I: Sync,
impl<I> Unpin for Slab<I> where
I: Unpin,
I: Unpin,
impl<I> UnwindSafe for Slab<I> where
I: UnwindSafe,
I: UnwindSafe,
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, 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>,