pub struct IndexMap<K: Borrow<usize> + Default, V, const N: usize> { /* private fields */ }Expand description
This is a fixed-size map that can store up to N consecutive elements.
Implementations§
Source§impl<K: Borrow<usize> + Default, V, const N: usize> IndexMap<K, V, N>
impl<K: Borrow<usize> + Default, V, const N: usize> IndexMap<K, V, N>
Sourcepub fn get(&self, index: &K) -> Option<&V>
pub fn get(&self, index: &K) -> Option<&V>
Get the element at the given index.
index - The index to get the element from.
Returns Some(&T) if the index is in-bounds, otherwise None.
Sourcepub fn get_mut(&mut self, index: &K) -> Option<&mut V>
pub fn get_mut(&mut self, index: &K) -> Option<&mut V>
Get a mutable reference to the element at the given index.
index - The index to get the element from.
Returns Some(&mut T) if the index is in-bounds, otherwise None.
Sourcepub fn insert(&mut self, index: &K, value: V) -> Result<(), KernelError>
pub fn insert(&mut self, index: &K, value: V) -> Result<(), KernelError>
Insert a value at the given index.
index - The index to insert the value at.
value - The value to insert.
Returns Ok(()) if the index was in-bounds, otherwise Err(KernelError::OutOfMemory).
Sourcepub fn insert_next(&mut self, value: V) -> Result<usize, KernelError>
pub fn insert_next(&mut self, value: V) -> Result<usize, KernelError>
Insert a value at the next available index.
value - The value to insert.
Returns Ok(index) if the value was inserted, otherwise Err(KernelError::OutOfMemory).
Sourcepub fn remove(&mut self, index: &K) -> Option<V>
pub fn remove(&mut self, index: &K) -> Option<V>
Remove the value at the given index.
index - The index to remove the value from.
Returns the value if it was removed, otherwise None.
Sourcepub fn iter(&self) -> impl Iterator<Item = &Option<V>>
pub fn iter(&self) -> impl Iterator<Item = &Option<V>>
Get an iterator over the elements in the map.
Returns an iterator over the elements in the map.
Sourcepub fn iter_from_cycle(&self, index: &K) -> impl Iterator<Item = &Option<V>>
pub fn iter_from_cycle(&self, index: &K) -> impl Iterator<Item = &Option<V>>
Get an cycling iterator over the elements in the map, starting from the given index.
index - The index to start the iterator from.
Returns an iterator over the elements in the map.
Sourcepub fn next(&self, index: Option<&K>) -> Option<usize>
pub fn next(&self, index: Option<&K>) -> Option<usize>
Get the next index that contains a value (this will cycle).
index - The index to start the search from.
Returns the next index (potentially < index) that contains a value, otherwise None.