Struct slotmapvec::SlotMapVec
source · pub struct SlotMapVec<T> { /* private fields */ }
Expand description
Slot map: array storage with persistent indices
See module documentation for more details.
Implementations
sourceimpl<T> SlotMapVec<T>
impl<T> SlotMapVec<T>
sourcepub fn new() -> SlotMapVec<T>
pub fn new() -> SlotMapVec<T>
Construct a new, empty SlotMapVec
.
The function does not allocate.
Examples
let slotmap :SlotMapVec<i32> = SlotMapVec::new();
sourcepub fn with_capacity(capacity: usize) -> SlotMapVec<T>
pub fn with_capacity(capacity: usize) -> SlotMapVec<T>
Construct a new SlotMapVec
with the specified capacity.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of values the map can store without reallocating.
sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
Return an iterator over all elements of the map along with their index.
Examples
let mut map = SlotMapVec::new();
for i in 0..3 {
map.insert(i);
}
let mut i = 0;
for (idx,val) in map.iter() {
assert_eq!(*val, i);
i += 1;
}
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
Return an iterator over mutable references to all elements of the map along with their index.
Examples
let mut map = SlotMapVec::new();
for i in 0..3 {
map.insert(i);
}
let mut i = 0;
for (idx,val) in map.iter_mut() {
*val *= 2;
assert_eq!(*val, i);
i += 2;
}
sourcepub fn get(&self, key: SlotMapIndex) -> Option<&T>
pub fn get(&self, key: SlotMapIndex) -> Option<&T>
Returns a reference to the value associated with the given key.
If the given key is not associated with a values, then None
is
returned.
sourcepub fn get_mut(&mut self, key: SlotMapIndex) -> Option<&mut T>
pub fn get_mut(&mut self, key: SlotMapIndex) -> Option<&mut T>
Returns a mutable reference to the value associated with the given key.
If the given key is not associated with a values, then None
is
returned.
sourcepub fn insert(&mut self, val: T) -> SlotMapIndex
pub fn insert(&mut self, val: T) -> SlotMapIndex
Insert a value into the map, returning the index to the value.
The returned index will always refer uniquely to the inserted value (though it may be mutated), even after objects have been deleted and inserted into the same storage slot.
Examples
let mut map = SlotMapVec::new();
let key = map.insert("hello");
assert_eq!(map[key], "hello");
sourcepub fn remove(&mut self, key: SlotMapIndex) -> Option<T>
pub fn remove(&mut self, key: SlotMapIndex) -> Option<T>
Removes and returs the value associated with the given key.
The key is never reused in this map, except if the underlying storage type overflows.
sourcepub fn contains(&self, key: SlotMapIndex) -> bool
pub fn contains(&self, key: SlotMapIndex) -> bool
Return true
if a value is associated with the given key.
Trait Implementations
sourceimpl<T: Clone> Clone for SlotMapVec<T>
impl<T: Clone> Clone for SlotMapVec<T>
sourcefn clone(&self) -> SlotMapVec<T>
fn clone(&self) -> SlotMapVec<T>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<T: Debug> Debug for SlotMapVec<T>
impl<T: Debug> Debug for SlotMapVec<T>
sourceimpl<T> Default for SlotMapVec<T>
impl<T> Default for SlotMapVec<T>
sourceimpl<T> Index<SlotMapIndex> for SlotMapVec<T>
impl<T> Index<SlotMapIndex> for SlotMapVec<T>
sourceimpl<T> IndexMut<SlotMapIndex> for SlotMapVec<T>
impl<T> IndexMut<SlotMapIndex> for SlotMapVec<T>
sourcefn index_mut(&mut self, key: SlotMapIndex) -> &mut T
fn index_mut(&mut self, key: SlotMapIndex) -> &mut T
container[index]
) operation. Read more