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
sourceimpl<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
sourceimpl<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 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
Trait Implementations
sourceimpl<'de, K: Deserialize<'de> + Indexable, V: Deserialize<'de>, const N: usize> Deserialize<'de> for ArrayMap<K, V, N>
impl<'de, K: Deserialize<'de> + Indexable, V: Deserialize<'de>, const N: usize> Deserialize<'de> for ArrayMap<K, V, N>
sourcefn deserialize<D>(
deserializer: D
) -> Result<Self, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<Self, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<K: Indexable, const M: usize, const S: usize> From<&'_ ArrayMap<K, AtomicBool, M>> for ArraySet<K, S>
impl<K: Indexable, const M: usize, const S: usize> From<&'_ ArrayMap<K, AtomicBool, M>> for ArraySet<K, S>
sourcefn from(m: &ArrayMap<K, AtomicBool, M>) -> Self
fn from(m: &ArrayMap<K, AtomicBool, M>) -> Self
Converts to this type from the input type.
sourceimpl<K: Indexable, const M: usize, const S: usize> From<ArrayMap<K, bool, M>> for ArraySet<K, S>
impl<K: Indexable, const M: usize, const S: usize> From<ArrayMap<K, bool, M>> for ArraySet<K, S>
sourceimpl<K: Indexable, const M: usize, const S: usize> From<ArraySet<K, S>> for ArrayMap<K, bool, M>
impl<K: Indexable, const M: usize, const S: usize> From<ArraySet<K, S>> for ArrayMap<K, bool, M>
sourceimpl<K: Indexable, const M: usize, const S: usize> From<ArraySet<K, S>> for ArrayMap<K, AtomicBool, M>
impl<K: Indexable, const M: usize, const S: usize> From<ArraySet<K, S>> for ArrayMap<K, AtomicBool, M>
sourceimpl<K: Indexable, V, const N: usize> IntoIterator for ArrayMap<K, V, N>
impl<K: Indexable, V, const N: usize> IntoIterator for ArrayMap<K, V, N>
sourceimpl<K: Serialize + Indexable, V: Serialize, const N: usize> Serialize for ArrayMap<K, V, N>
impl<K: Serialize + Indexable, V: Serialize, const N: usize> Serialize for ArrayMap<K, V, N>
sourcefn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<K, V: Copy, const N: usize> Copy for ArrayMap<K, V, N>
impl<K, V: Eq, const N: usize> Eq for ArrayMap<K, V, N>
impl<K, V: Send, const N: usize> Send for ArrayMap<K, V, N>
impl<K, V: Sync, const N: usize> Sync for ArrayMap<K, V, N>
impl<K, V: Unpin, const N: usize> Unpin for ArrayMap<K, V, N>
impl<K, V: UnwindSafe, const N: usize> UnwindSafe for ArrayMap<K, V, N>
Auto Trait Implementations
impl<K, V, const N: usize> RefUnwindSafe for ArrayMap<K, V, N> where
K: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more