pub struct OrdinalTotalMap<T, V> { /* private fields */ }Expand description
Map implementation where all values must be initialized at creation.
This version of map allocates values on the heap in a single contiguous block.
For a version that doesn’t require heap allocation,
see InitArrayMap.
Implementations§
Source§impl<K: Ordinal, V> OrdinalTotalMap<K, V>
impl<K: Ordinal, V> OrdinalTotalMap<K, V>
Sourcepub fn try_new<E>(init: impl FnMut(K) -> Result<V, E>) -> Result<Self, E>
pub fn try_new<E>(init: impl FnMut(K) -> Result<V, E>) -> Result<Self, E>
Create a new map by initializing each value with a function.
Sourcepub fn new(init: impl FnMut(K) -> V) -> Self
pub fn new(init: impl FnMut(K) -> V) -> Self
Create a new map by initializing each value with a function.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of elements in the map, which is
always equal to K::ORDINAL_SIZE.
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Return true if the map container no elements.
This is only if <K> is empty.
Sourcepub fn get<'a>(&'a self, key: &K) -> &'a V
pub fn get<'a>(&'a self, key: &K) -> &'a V
Returns a reference to the value corresponding to the key.
Sourcepub fn get_mut<'a>(&'a mut self, key: &K) -> &'a mut V
pub fn get_mut<'a>(&'a mut self, key: &K) -> &'a mut V
Returns a mutable reference to the value corresponding to the key.
Sourcepub fn keys(&self) -> OrdinalValues<K> ⓘ
pub fn keys(&self) -> OrdinalValues<K> ⓘ
Iterate keys of the map, which is equivalent to iterating all possible values of K.
Sourcepub fn into_keys(self) -> OrdinalValues<K> ⓘ
pub fn into_keys(self) -> OrdinalValues<K> ⓘ
Iterate values of the map, which is equivalent to iterating all possible values of K.
Sourcepub fn values_mut<'a>(&'a mut self) -> IterMut<'a, V>
pub fn values_mut<'a>(&'a mut self) -> IterMut<'a, V>
Iterate mutable references to values of the map.
Sourcepub fn into_values(self) -> Box<[V]>
pub fn into_values(self) -> Box<[V]>
Obtain the values from the map.