pub struct Slab<I>where
I: Id,{ /* private fields */ }
Expand description
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());
Implementations§
Source§impl<I> Slab<I>where
I: Id,
impl<I> Slab<I>where
I: Id,
Sourcepub fn new() -> Self
pub fn new() -> Self
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());
Trait Implementations§
Auto Trait Implementations§
impl<I> Freeze for Slab<I>where
I: Freeze,
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more