[][src]Struct slab::Slab

pub struct Slab<T, I: Index> { /* fields omitted */ }

A preallocated chunk of memory for storing objects of the same type.

Methods

impl<T, I: Index> Slab<T, I>[src]

pub fn new(capacity: usize) -> Slab<T, I>[src]

pub fn new_starting_at(offset: I, capacity: usize) -> Slab<T, I>[src]

pub fn count(&self) -> usize[src]

pub fn is_empty(&self) -> bool[src]

pub fn remaining(&self) -> usize[src]

pub fn has_remaining(&self) -> bool[src]

pub fn contains(&self, idx: I) -> bool[src]

pub fn get(&self, idx: I) -> Option<&T>[src]

pub fn get_mut(&mut self, idx: I) -> Option<&mut T>[src]

pub fn insert(&mut self, val: T) -> Result<I, T>[src]

pub fn insert_with<F>(&mut self, fun: F) -> Option<I> where
    F: FnOnce(I) -> T, 
[src]

Like insert but for objects that require newly allocated usize in their constructor.

pub fn remove(&mut self, idx: I) -> Option<T>[src]

Releases the given slot

pub fn replace(&mut self, idx: I, t: T) -> Option<T>[src]

pub fn replace_with<F>(&mut self, idx: I, fun: F) -> Result<(), ()> where
    F: FnOnce(T) -> Option<T>, 
[src]

Execute a function on the value in the slot and put the result of the function back into the slot. If function returns None, slot is left empty on exit.

Returns Err(()) if slot was empty

This method is very useful for storing state machines inside Slab

pub fn retain<F>(&mut self, fun: F) where
    F: FnMut(&T) -> bool
[src]

Retain only the elements specified by the predicate.

In other words, remove all elements e such that f(&e) returns false. This method operates in place and preserves the order of the retained elements.

Important traits for SlabIter<'a, T, I>
pub fn iter(&self) -> SlabIter<T, I>[src]

Important traits for SlabMutIter<'a, T, I>
pub fn iter_mut(&mut self) -> SlabMutIter<T, I>[src]

pub fn clear(&mut self)[src]

Empty the slab, by freeing all entries

pub fn grow(&mut self, entries_num: usize)[src]

Grow the slab, by adding entries_num

Trait Implementations

impl<T, I: Index> Send for Slab<T, I> where
    T: Send
[src]

impl<'a, T, I: Index> IntoIterator for &'a Slab<T, I>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = SlabIter<'a, T, I>

Which kind of iterator are we turning this into?

impl<'a, T, I: Index> IntoIterator for &'a mut Slab<T, I>[src]

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = SlabMutIter<'a, T, I>

Which kind of iterator are we turning this into?

impl<T, I: Index> Debug for Slab<T, I>[src]

impl<T, I: Index> Index<I> for Slab<T, I>[src]

type Output = T

The returned type after indexing.

impl<T, I: Index> IndexMut<I> for Slab<T, I>[src]

Auto Trait Implementations

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

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

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

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

Blanket Implementations

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

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

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.

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

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

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