Struct ArrayMap

Source
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, V, const N: usize> ArrayMap<K, V, N>

Source

pub const fn new(array: [V; N]) -> Self

Function that can be used in const contexts to get a new ArrayMap.

Callers should ensure that each V in the array matches the return of index() from K to get back expected results.

Source§

impl<K: Indexable, V: Clone, const N: usize> ArrayMap<K, V, N>

Source

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>

Source

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

Source

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

Source

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

Source

pub fn from_options<E, I: IntoIterator<Item = (K, Option<V>)>>( iter: I, ) -> Option<Self>

Collects an iterator of (K, Option<V>) into an Option<Self>

Returns None if any of the values is None or if the iterator isn’t long enough.

§Panics

Panics if any of the safety requirements in the Indexable trait are wrong

Source

pub fn from_iter<E, I: IntoIterator<Item = (K, V)>>(iter: I) -> Option<Self>

Collects an iterator of (K, V) into an Option<Self>

Returns None if there aren’t enough elements, or not all values of K have been seen.

§Panics

Panics if any of the safety requirements in the Indexable trait are wrong

Source

pub fn iter(&self) -> impl Iterator<Item = (K, &V)> + '_

Returns an iterator over all the items in the map. Note that the keys are owned.

§Panics

Panics if any of the safety requirements in the Indexable trait are wrong

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (K, &mut V)> + '_

Returns a mutable iterator over all the items in the map

§Panics

Panics if any of the safety requirements in the Indexable trait are wrong

Source

pub fn keys(&self) -> impl Iterator<Item = K> + '_

Returns an iterator over all the keys in the map. Note that the keys are owned.

Source

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

Source

pub fn each_ref(&self) -> ArrayMap<K, &V, N>

Turns this into an array of references to the original. Useful for calling map when all you need are references

§Panics

Can only panic if K::iter() is unstable or doesn’t meet requirements

Source

pub fn map<U, F: FnMut(&K, V) -> U>(self, f: F) -> ArrayMap<K, U, N>

Maps all values in this map using the provided function

§Panics

Can only panic if K::iter() is unstable or doesn’t meet requirements

Source§

impl<K, V, const N: usize> ArrayMap<K, V, N>

Source

pub fn values(&self) -> impl Iterator<Item = &V> + '_

Returns an iterator over all the values in the map

Source

pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V> + '_

Returns a mutable iterator over all the values in the map

Trait Implementations§

Source§

impl<K, V, const N: usize> AsMut<[V]> for ArrayMap<K, V, N>

Source§

fn as_mut(&mut self) -> &mut [V]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<K, V, const N: usize> AsMut<[V; N]> for ArrayMap<K, V, N>

Source§

fn as_mut(&mut self) -> &mut [V; N]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<K, V, const N: usize> AsRef<[V]> for ArrayMap<K, V, N>

Source§

fn as_ref(&self) -> &[V]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<K, V, const N: usize> AsRef<[V; N]> for ArrayMap<K, V, N>

Source§

fn as_ref(&self) -> &[V; N]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<K, V: Clone, const N: usize> Clone for ArrayMap<K, V, N>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug + Indexable, V: Debug, const N: usize> Debug for ArrayMap<K, V, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: Indexable, V: Default, const N: usize> Default for ArrayMap<K, V, N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, K: Deserialize<'de> + Indexable, V: Deserialize<'de>, const N: usize> Deserialize<'de> for ArrayMap<K, V, N>

Source§

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
Source§

impl<K: Indexable, const M: usize, const S: usize> From<&ArrayMap<K, AtomicBool, M>> for ArraySet<K, S>

Source§

fn from(m: &ArrayMap<K, AtomicBool, M>) -> Self

Converts to this type from the input type.
Source§

impl<K: Indexable, const M: usize, const S: usize> From<ArrayMap<K, bool, M>> for ArraySet<K, S>

Source§

fn from(m: ArrayMap<K, bool, M>) -> Self

Converts to this type from the input type.
Source§

impl<K: Indexable, const M: usize, const S: usize> From<ArraySet<K, S>> for ArrayMap<K, AtomicBool, M>

Source§

fn from(s: ArraySet<K, S>) -> Self

Converts to this type from the input type.
Source§

impl<K: Indexable, const M: usize, const S: usize> From<ArraySet<K, S>> for ArrayMap<K, bool, M>

Source§

fn from(s: ArraySet<K, S>) -> Self

Converts to this type from the input type.
Source§

impl<K: Indexable, V, const N: usize> FromIterator<(K, V)> for ArrayMap<K, Option<V>, N>

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<K: Indexable, V, const N: usize> FromIterator<(K, V)> for ArrayMap<K, V, N>

Source§

fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<K: Indexable, V, const N: usize> Index<K> for ArrayMap<K, V, N>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, index: K) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<K: Indexable, V, const N: usize> Index<usize> for ArrayMap<K, V, N>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<K: Indexable, V, const N: usize> IndexMut<K> for ArrayMap<K, V, N>

Source§

fn index_mut(&mut self, index: K) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<K: Indexable, V, const N: usize> IndexMut<usize> for ArrayMap<K, V, N>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<K: Indexable, V, const N: usize> IntoIterator for ArrayMap<K, V, N>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = Zip<<K as Indexable>::Iter, IntoIter<V, N>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, V: PartialEq, const N: usize> PartialEq for ArrayMap<K, V, N>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K: Serialize + Indexable, V: Serialize, const N: usize> Serialize for ArrayMap<K, V, N>

Source§

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
Source§

impl<K, V: Copy, const N: usize> Copy for ArrayMap<K, V, N>

Source§

impl<K, V: Eq, const N: usize> Eq for ArrayMap<K, V, N>

Source§

impl<K, V: Send, const N: usize> Send for ArrayMap<K, V, N>

Source§

impl<K, V: Sync, const N: usize> Sync for ArrayMap<K, V, N>

Source§

impl<K, V: Unpin, const N: usize> Unpin for ArrayMap<K, V, N>

Source§

impl<K, V: UnwindSafe, const N: usize> UnwindSafe for ArrayMap<K, V, N>

Auto Trait Implementations§

§

impl<K, V, const N: usize> Freeze for ArrayMap<K, V, N>
where V: Freeze,

§

impl<K, V, const N: usize> RefUnwindSafe for ArrayMap<K, V, N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,