[−][src]Struct ochenslab::OchenSlab
Limited size preallocated slab storage that won't reallocate ever
Example
use ochenslab::OchenSlab; let mut slab = OchenSlab::<usize>::with_capacity(2); let a = slab.insert(31337); let b = slab.insert(31338); assert!(a.is_some()); assert!(b.is_some()); // at this point container is at its max capacity let c = slab.insert(31339); assert!(c.is_none()); assert_eq!(*slab.get(a.unwrap()).unwrap(), 31337); assert_eq!(*slab.get(b.unwrap()).unwrap(), 31338);
Methods
impl<T> OchenSlab<T>
[src]
pub fn with_capacity(capacity: usize) -> OchenSlab<T>
[src]
Create slab instance with given capacity Capacity will be constant for the entire lifetime of this object and cannot increase
pub fn len(&self) -> usize
[src]
Return number of elements in this container
pub fn get(&self, index: usize) -> Option<&T>
[src]
Get reference to an item by its index
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
[src]
Get mutable reference to an item by its index
pub fn insert(&mut self, t: T) -> Option<usize>
[src]
Insert a new item and return its index. Returns None if there's no space left Contrary to Rust opinion this cannot affect any other items in this container, so it is safe to hold a mutable reference to some other item while inserting another. This is because insert will not ever reallocate, so it can't invalidate existing pointers.
pub fn remove(&mut self, index: usize) -> Option<T>
[src]
Remove an item by its index. Returns the item by value if there was one
Auto Trait Implementations
impl<T> RefUnwindSafe for OchenSlab<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for OchenSlab<T> where
T: Send,
T: Send,
impl<T> Sync for OchenSlab<T> where
T: Sync,
T: Sync,
impl<T> Unpin for OchenSlab<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for OchenSlab<T> where
T: UnwindSafe,
T: 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>,