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>
[src]
fn new(capacity: usize) -> Slab<T, I>
fn new_starting_at(offset: I, capacity: 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 vacant_entry(&mut self) -> Option<VacantEntry<I, T>>
fn entry(&mut self, idx: I) -> Option<Entry<I, T>>
fn insert_with<F>(&mut self, fun: F) -> Option<I> where F: FnOnce(I) -> T
Like insert
but for objects that require newly allocated
usize in their constructor.
NOTE: This method is deprecated in favor of the entry
API.
fn insert_with_opt<F>(&mut self, fun: F) -> Option<I> where F: FnOnce(I) -> Option<T>
Like insert_with
but allows function to return nothing instead of
a value.
This is useful for mio when you need a token to register a socket but socket registration might fail so you don't have anything useful to insert.
NOTE: This method is deprecated in favor of the entry
API.
fn remove(&mut self, idx: I) -> Option<T>
Releases the given slot
fn replace(&mut self, idx: I, t: T) -> Option<T>
Replace the given slot, if the slot being replaced was empty, then we increment the len of the slab
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
NOTE: This method is deprecated in favor of the entry
API.
fn retain<F>(&mut self, fun: F) where F: FnMut(&T) -> bool
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.
fn iter(&self) -> SlabIter<T, I>
fn iter_mut(&mut self) -> SlabMutIter<T, I>
fn clear(&mut self)
Empty the slab, by freeing all entries
fn grow(&mut self, entries_num: usize)
Grow the slab, by adding entries_num
Trait Implementations
impl<T, I: Index> Send for Slab<T, I> where T: Send
[src]
impl<T, I: Index> Index<I> for Slab<T, I>
[src]
type Output = T
The returned type after indexing
fn index(&self, index: I) -> &T
The method for the indexing (Foo[Bar]
) operation
impl<T, I: Index> IndexMut<I> for Slab<T, I>
[src]
fn index_mut(&mut self, index: I) -> &mut T
The method for the indexing (Foo[Bar]
) operation
impl<T, I: Index> Debug for Slab<T, I>
[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?
fn into_iter(self) -> SlabIter<'a, T, I>
Creates an iterator from a value. Read more
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?
fn into_iter(self) -> SlabMutIter<'a, T, I>
Creates an iterator from a value. Read more