[−][src]Struct logicsim::data_structures::Slab
Simple slab allocator. Stores items of the same type and can reuse removed indexes.
Example
let mut s = Slab::new(); let index = s.insert(5); assert_eq!(s.get(index), Some(&5)); assert_eq!(s.remove(index), Some(5)); assert_eq!(s.get(index), None);
Implementations
impl<T: Sized> Slab<T>
[src]
pub fn new() -> Self
[src]
Returns an empty Slab.
pub fn insert(&mut self, item: T) -> SlabIndex
[src]
Inserts an item into the slab and returns its index.
Will reuse an empty index if one is available.
pub fn get_mut(&mut self, index: SlabIndex) -> Option<&mut T>
[src]
Returns a mutable reference to the item at index
.
Returns None if index
has been removed.
pub fn get(&self, index: SlabIndex) -> Option<&T>
[src]
Return a reference to the item at index
.
Returns None if index
has been removed.
pub fn remove(&mut self, index: SlabIndex) -> Option<T>
[src]
Removes an item from the Slab and returns it.
Returns None if index
has been removed.
index
will be reused on the next call to Slab::insert.
pub fn len(&self) -> usize
[src]
Returns the number of items in the slab.
This is different from the number of allocated slots in the slab, see Slab::total_len
pub fn is_empty(&self) -> bool
[src]
Returns true if the number of items in the slab is 0.
This is different from the number of allocated slots in the slab, see Slab::total_len
pub fn total_len(&self) -> usize
[src]
Returns the number of allocated slots in the slab, some of them could be empty.
pub fn iter(&self) -> Iter<'_, T>
[src]
Returns an iterator over pairs of (SlabIndex, [&T])
.
pub unsafe fn get_very_unsafely(&self, index: SlabIndex) -> &T
[src]
Returns the item at index without performing bounds checking or checking if the slot contains initialized data.
Safety
This function is safe if index
< Slab::total_len()
and the item at index
has not been removed.
Will panic in debug mode if the invariants are broken.
Annoyingly long names discourage use and make you really think about what you are doing.
Trait Implementations
impl<T: Clone + Sized> Clone for Slab<T>
[src]
impl<T: Debug + Sized> Debug for Slab<T>
[src]
impl<T> Default for Slab<T>
[src]
impl<T> IntoIterator for Slab<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Slab<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Slab<T> where
T: Send,
T: Send,
impl<T> Sync for Slab<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Slab<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Slab<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,
pub 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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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.
pub 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>,