[−][src]Struct enum_map_internals::EnumMap
An enum mapping.
This internally uses an array which stores a value for each possible
enum value. To work, it requires implementation of internal (private,
although public due to macro limitations) trait which allows extracting
information about an enum, which can be automatically generated using
#[derive(EnumMap)]
macro.
Additionally, bool
and u8
automatically derives from EnumMap
. While
u8
is not technically an enum, it's convenient to consider it like one.
In particular, reverse-complement in benchmark game could be using u8
as an enum.
Examples
use enum_map::{enum_map, Enum, EnumMap}; #[derive(Enum)] enum Example { A, B, C, } fn main() { let mut map = EnumMap::new(); // new initializes map with default values assert_eq!(map[Example::A], 0); map[Example::A] = 3; assert_eq!(map[Example::A], 3); }
Methods
impl<K: Enum<V>, V> EnumMap<K, V>
[src]
ⓘImportant traits for Values<'a, V>pub fn values(&self) -> Values<V>
[src]
An iterator visiting all values. The iterator type is &V
.
Examples
use enum_map::enum_map; fn main() { let map = enum_map! { false => 3, true => 4 }; let mut values = map.values(); assert_eq!(values.next(), Some(&3)); assert_eq!(values.next(), Some(&4)); assert_eq!(values.next(), None); }
ⓘImportant traits for ValuesMut<'a, V>pub fn values_mut(&mut self) -> ValuesMut<V>
[src]
An iterator visiting all values mutably. The iterator type is &mut V
.
Examples
use enum_map::enum_map; fn main() { let mut map = enum_map! { _ => 2 }; for value in map.values_mut() { *value += 2; } assert_eq!(map[false], 4); assert_eq!(map[true], 4); }
impl<K: Enum<V>, V: Default> EnumMap<K, V>
[src]
pub fn new() -> Self
[src]
Creates an enum map with default values.
Examples
use enum_map::{Enum, EnumMap}; #[derive(Enum)] enum Example { A, } fn main() { let enum_map = EnumMap::<_, i32>::new(); assert_eq!(enum_map[Example::A], 0); }
impl<K: Enum<V>, V> EnumMap<K, V>
[src]
ⓘImportant traits for Iter<'a, K, V>pub fn iter(&self) -> Iter<K, V>
[src]
Returns an iterator over enum map.
ⓘImportant traits for IterMut<'a, K, V>pub fn iter_mut(&mut self) -> IterMut<K, V>
[src]
Returns a mutable iterator over enum map.
pub fn len(&self) -> usize
[src]
Returns number of elements in enum map.
pub fn is_empty(&self) -> bool
[src]
Returns whether the enum variant set is empty.
This isn't particularly useful, as there is no real reason to use enum map for enums without variants. However, it is provided for consistency with data structures providing len method (and I will admit, to avoid clippy warnings).
Examples
use enum_map::{Enum, EnumMap}; #[derive(Enum)] enum Void {} #[derive(Enum)] enum SingleVariant { Variant, } fn main() { assert!(EnumMap::<Void, ()>::new().is_empty()); assert!(!EnumMap::<SingleVariant, ()>::new().is_empty()); }
pub fn swap(&mut self, a: K, b: K)
[src]
Swaps two indexes.
Examples
use enum_map::enum_map; fn main() { let mut map = enum_map! { false => 0, true => 1 }; map.swap(false, true); assert_eq!(map[false], 1); assert_eq!(map[true], 0); }
pub fn as_slice(&self) -> &[V]
[src]
Converts an enum map to a slice representing values.
pub fn as_mut_slice(&mut self) -> &mut [V]
[src]
Converts a mutable enum map to a mutable slice representing values.
pub fn as_ptr(&self) -> *const V
[src]
Returns a raw pointer to the enum map's slice.
The caller must ensure that the slice outlives the pointer this function returns, or else it will end up pointing to garbage.
Examples
use enum_map::{enum_map, EnumMap}; fn main() { let map = enum_map! { 5 => 42, _ => 0 }; assert_eq!(unsafe { *map.as_ptr().offset(5) }, 42); }
pub fn as_mut_ptr(&mut self) -> *mut V
[src]
Returns an unsafe mutable pointer to the enum map's slice.
The caller must ensure that the slice outlives the pointer this function returns, or else it will end up pointing to garbage.
Examples
use enum_map::{enum_map, EnumMap}; fn main() { let mut map = enum_map! { _ => 0 }; unsafe { *map.as_mut_ptr().offset(11) = 23 }; assert_eq!(map[11], 23); }
Trait Implementations
impl<K: Enum<V>, V: PartialEq> PartialEq<EnumMap<K, V>> for EnumMap<K, V>
[src]
fn eq(&self, other: &Self) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<K: Enum<V>, V: Eq> Eq for EnumMap<K, V>
[src]
impl<K: Enum<V>, V: Hash> Hash for EnumMap<K, V>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<K: Enum<V> + Debug, V: Debug> Debug for EnumMap<K, V>
[src]
impl<K: Enum<V>, V> Index<K> for EnumMap<K, V>
[src]
impl<K: Enum<V>, V> IndexMut<K> for EnumMap<K, V>
[src]
impl<K: Enum<V>, V> Copy for EnumMap<K, V> where
K::Array: Copy,
[src]
K::Array: Copy,
impl<K: Enum<V>, V> Extend<(K, V)> for EnumMap<K, V>
[src]
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)
[src]
impl<'a, K, V> Extend<(&'a K, &'a V)> for EnumMap<K, V> where
K: Enum<V> + Copy,
V: Copy,
[src]
K: Enum<V> + Copy,
V: Copy,
fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I)
[src]
impl<'a, K: Enum<V>, V> IntoIterator for &'a EnumMap<K, V>
[src]
type Item = (K, &'a V)
The type of the elements being iterated over.
type IntoIter = Iter<'a, K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, K: Enum<V>, V> IntoIterator for &'a mut EnumMap<K, V>
[src]
type Item = (K, &'a mut V)
The type of the elements being iterated over.
type IntoIter = IterMut<'a, K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<K: Enum<V>, V> IntoIterator for EnumMap<K, V>
[src]
type Item = (K, V)
The type of the elements being iterated over.
type IntoIter = IntoIter<K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<F: FnMut(K) -> V, K: Enum<V>, V> From<F> for EnumMap<K, V>
[src]
impl<K: Enum<V>, V> Clone for EnumMap<K, V> where
K::Array: Clone,
[src]
K::Array: Clone,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<K: Enum<V>, V: Default> Default for EnumMap<K, V>
[src]
Auto Trait Implementations
impl<K, V> Unpin for EnumMap<K, V> where
<K as Enum<V>>::Array: Unpin,
<K as Enum<V>>::Array: Unpin,
impl<K, V> Send for EnumMap<K, V> where
<K as Enum<V>>::Array: Send,
<K as Enum<V>>::Array: Send,
impl<K, V> Sync for EnumMap<K, V> where
<K as Enum<V>>::Array: Sync,
<K as Enum<V>>::Array: Sync,
Blanket Implementations
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,