[][src]Struct logicsim::data_structures::Slab

pub struct Slab<T: Sized> { /* fields omitted */ }

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]

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

type Item = (SlabIndex, T)

The type of the elements being iterated over.

Auto Trait Implementations

impl<T> RefUnwindSafe for Slab<T> where
    T: RefUnwindSafe

impl<T> Send for Slab<T> where
    T: Send

impl<T> Sync for Slab<T> where
    T: Sync

impl<T> Unpin for Slab<T> where
    T: Unpin

impl<T> UnwindSafe for Slab<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.