pub struct Slab<T, K: Key> { /* private fields */ }Expand description
A Slab which can hold some number of elements, depending on the chosen K.
§Examples
let mut slab = slabby::Slab32::new();
unsafe {
let key1 = slab.insert(1);
let key2 = slab.insert(2);
let key3 = slab.insert(3);
assert_eq!(slab.get(key1), &1);
assert_eq!(slab.get(key2), &2);
assert_eq!(slab.get(key3), &3);
assert_eq!(slab.remove(key2), 2);
assert_eq!(slab.remove(key1), 1);
assert_eq!(slab.get(key3), &3);
slab.insert(4);
let key5 = slab.insert(5);
slab.insert(6);
assert_eq!(slab.len(), 4);
*slab.get_mut(key5) += 1;
assert_eq!(slab.remove(key5), 6);
assert_eq!(slab.len(), 3);
}Implementations§
source§impl<T, K: Key> Slab<T, K>
impl<T, K: Key> Slab<T, K>
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Slab. No allocations will occur until the first Slab::insert.
Trait Implementations§
Auto Trait Implementations§
impl<T, K> Freeze for Slab<T, K>where
K: Freeze,
impl<T, K> RefUnwindSafe for Slab<T, K>where
K: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, K> Send for Slab<T, K>
impl<T, K> Sync for Slab<T, K>
impl<T, K> Unpin for Slab<T, K>where
K: Unpin,
impl<T, K> UnwindSafe for Slab<T, K>where
K: UnwindSafe,
T: 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