Struct enumoid::EnumMap

source ·
pub struct EnumMap<T: EnumArrayHelper<V>, V> { /* private fields */ }
Expand description

A total map from enumoid T to values V.

Implementations§

source§

impl<T: EnumArrayHelper<V>, V: Default> EnumMap<T, V>

source

pub fn new() -> Self

Creates a new map populated with default values.

source§

impl<T: EnumArrayHelper<V>, V> EnumMap<T, V>

source

pub fn new_with<F>(f: F) -> Self
where F: FnMut(T) -> V,

Creates a new map populated by a callback function.

source

pub fn as_slice(&self) -> &[V]

Returns a slice containing all the values in the map.

source

pub fn as_slice_mut(&mut self) -> &mut [V]

Returns a mutable slice containing all the values in the map.

source

pub fn get_by_index(&self, index: EnumIndex<T>) -> &V

Returns a reference to the value associated with a given index.

source

pub fn get(&self, key: T) -> &V

Returns a reference to the value associated with a given key.

source

pub fn get_by_index_mut(&mut self, index: EnumIndex<T>) -> &mut V

Returns a mutable reference to the value associated with a given index.

source

pub fn get_mut(&mut self, key: T) -> &mut V

Returns a mutable reference to the value associated with a given key.

source

pub fn swap(&mut self, a: T, b: T)

Swaps two elements in the map.

source

pub fn iter(&self) -> EnumSliceIter<'_, T, V>

Returns an iterator over the keys and elements.

source

pub fn iter_mut(&mut self) -> EnumSliceIterMut<'_, T, V>

Returns a mutable iterator over the keys and elements.

Trait Implementations§

source§

impl<T: EnumArrayHelper<V>, V: Clone> Clone for EnumMap<T, V>

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<T: EnumArrayHelper<V> + Debug, V: Debug> Debug for EnumMap<T, V>

source§

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

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

impl<T: EnumArrayHelper<V>, V: Default> Default for EnumMap<T, V>

source§

fn default() -> Self

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

impl<'de, T: EnumArrayHelper<V> + EnumSetHelper<u8> + Deserialize<'de>, V: Deserialize<'de>> Deserialize<'de> for EnumMap<T, V>

source§

fn deserialize<D>(de: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: EnumArrayHelper<V>, V: Hash> Hash for EnumMap<T, V>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: EnumArrayHelper<V>, V> Index<EnumIndex<T>> for EnumMap<T, V>

§

type Output = V

The returned type after indexing.
source§

fn index(&self, index: EnumIndex<T>) -> &V

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

impl<T: EnumArrayHelper<V>, V> Index<T> for EnumMap<T, V>

§

type Output = V

The returned type after indexing.
source§

fn index(&self, key: T) -> &V

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

impl<T: EnumArrayHelper<V>, V> IndexMut<EnumIndex<T>> for EnumMap<T, V>

source§

fn index_mut(&mut self, index: EnumIndex<T>) -> &mut V

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

impl<T: EnumArrayHelper<V>, V> IndexMut<T> for EnumMap<T, V>

source§

fn index_mut(&mut self, key: T) -> &mut V

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

impl<'a, T: EnumArrayHelper<V>, V> IntoIterator for &'a EnumMap<T, V>

§

type Item = (T, &'a V)

The type of the elements being iterated over.
§

type IntoIter = EnumSliceIter<'a, T, V>

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<'a, T: EnumArrayHelper<V>, V> IntoIterator for &'a mut EnumMap<T, V>

§

type Item = (T, &'a mut V)

The type of the elements being iterated over.
§

type IntoIter = EnumSliceIterMut<'a, T, V>

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<T: EnumArrayHelper<V>, V: PartialEq> PartialEq for EnumMap<T, V>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: EnumArrayHelper<V> + Serialize, V: Serialize> Serialize for EnumMap<T, V>

source§

fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: EnumArrayHelper<V> + EnumSetHelper<u8>, V> TryFrom<EnumOptionMap<T, V>> for EnumMap<T, V>

§

type Error = ()

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

fn try_from(from: EnumOptionMap<T, V>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: EnumArrayHelper<V>, V: Copy> Copy for EnumMap<T, V>
where T::TotalArray: Copy,

source§

impl<T: EnumArrayHelper<V>, V: Eq> Eq for EnumMap<T, V>

Auto Trait Implementations§

§

impl<T, V> RefUnwindSafe for EnumMap<T, V>

§

impl<T, V> Send for EnumMap<T, V>
where <T as EnumArrayHelper<V>>::TotalArray: Send,

§

impl<T, V> Sync for EnumMap<T, V>
where <T as EnumArrayHelper<V>>::TotalArray: Sync,

§

impl<T, V> Unpin for EnumMap<T, V>
where <T as EnumArrayHelper<V>>::TotalArray: Unpin,

§

impl<T, V> UnwindSafe for EnumMap<T, V>

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> 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,

§

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>,

§

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>,

§

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>,