pub struct ArrayMap<K, V, const N: usize> { /* private fields */ }
Expand description
A Map backed by an array. The keys must be known statically.
This map is O(1) for all operations. All members must be initialized at creation time so there is no option to insert or remove items from the map. Because of this it can be indexed into using the key type.
Implementations§
Source§impl<K: Indexable, V: Clone, const N: usize> ArrayMap<K, V, N>
impl<K: Indexable, V: Clone, const N: usize> ArrayMap<K, V, N>
Sourcepub fn from_value(v: V) -> Self
pub fn from_value(v: V) -> Self
Returns a new ArrayMap
where all the values are initialized to the same value
Source§impl<K: Indexable, V, const N: usize> ArrayMap<K, V, N>
impl<K: Indexable, V, const N: usize> ArrayMap<K, V, N>
Sourcepub fn from_closure<F: FnMut(&K) -> V>(f: F) -> Self
pub fn from_closure<F: FnMut(&K) -> V>(f: F) -> Self
Returns a new ArrayMap
where all the values are initialized to the value returned from each call of the closure.
§Panics
Panics if K::iter()
returns anything other than N
items or if K::index()
returns a value >= N
Sourcepub fn try_from_closure<E, F: FnMut(&K) -> Result<V, E>>(
f: F,
) -> Result<Self, E>
pub fn try_from_closure<E, F: FnMut(&K) -> Result<V, E>>( f: F, ) -> Result<Self, E>
Returns a new ArrayMap
where all the values are initialized to the same value
§Errors
Returns an error the first time that the provided closure returns an error.
§Panics
Panics if K::iter()
returns anything other than N
items or if K::index()
returns a value >= N
Sourcepub fn from_results<E, I: IntoIterator<Item = (K, Result<V, E>)>>(
iter: I,
) -> Result<Self, E>
pub fn from_results<E, I: IntoIterator<Item = (K, Result<V, E>)>>( iter: I, ) -> Result<Self, E>
Collects an iterator of (K, Result<V, E>)
into a Result<Self, E>
The trait FromIterator
cannot be implemented for Result
like it is on a Vec because of the orphan rules.
§Errors
Returns an error with the first emitted error from the provided iterator
§Panics
Panics if any of the safety requirements in the Indexable
trait are wrong
Sourcepub fn from_options<E, I: IntoIterator<Item = (K, Option<V>)>>(
iter: I,
) -> Option<Self>
pub fn from_options<E, I: IntoIterator<Item = (K, Option<V>)>>( iter: I, ) -> Option<Self>
Sourcepub fn from_iter<E, I: IntoIterator<Item = (K, V)>>(iter: I) -> Option<Self>
pub fn from_iter<E, I: IntoIterator<Item = (K, V)>>(iter: I) -> Option<Self>
Sourcepub fn keys(&self) -> impl Iterator<Item = K> + '_
pub fn keys(&self) -> impl Iterator<Item = K> + '_
Returns an iterator over all the keys in the map. Note that the keys are owned.
Sourcepub fn each_mut(&mut self) -> ArrayMap<K, &mut V, N>
pub fn each_mut(&mut self) -> ArrayMap<K, &mut V, N>
Turns this into an array of mutable references to the original.
Useful for calling map
when all you need are mutable references
§Panics
Can only panic if K::iter()
is unstable or doesn’t meet requirements