Struct slab::Slab [] [src]

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

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

Methods

impl<T, I: Index> Slab<T, I>

fn new(cap: usize) -> Slab<T, I>

fn new_starting_at(offset: I, cap: usize) -> Slab<T, I>

fn count(&self) -> usize

fn is_empty(&self) -> bool

fn remaining(&self) -> usize

fn has_remaining(&self) -> bool

fn contains(&self, idx: I) -> bool

fn get(&self, idx: I) -> Option<&T>

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

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

fn insert_with<F>(&mut self, f: F) -> Option<I> where F: FnOnce(I) -> T

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

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

Releases the given slot

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

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

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

fn iter(&self) -> SlabIter<T, I>

fn iter_mut(&mut self) -> SlabMutIter<T, I>

Trait Implementations

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

impl<T, I: Index> Index<I> for Slab<T, I>

type Output = T

fn index<'a>(&'a self, idx: I) -> &'a T

impl<T, I: Index> IndexMut<I> for Slab<T, I>

fn index_mut<'a>(&'a mut self, idx: I) -> &'a mut T

impl<T, I: Index> Debug for Slab<T, I>

fn fmt(&self, fmt: &mut Formatter) -> Result

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

type Item = &'a T

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

fn into_iter(self) -> SlabIter<'a, T, I>

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

type Item = &'a mut T

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

fn into_iter(self) -> SlabMutIter<'a, T, I>