Struct enum_map::EnumMap [−][src]
pub struct EnumMap<K: Internal<V>, V> { /* fields omitted */ }
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
#[macro_use] extern crate enum_map; use enum_map::EnumMap; #[derive(EnumMap)] 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: Internal<V>, V: Default> EnumMap<K, V>[src]
impl<K: Internal<V>, V: Default> EnumMap<K, V>pub fn new() -> Self[src]
pub fn new() -> SelfCreates an enum map with default values.
Examples
#[macro_use] extern crate enum_map; use enum_map::EnumMap; #[derive(EnumMap)] enum Example { A, } fn main() { let enum_map = EnumMap::<_, i32>::new(); assert_eq!(enum_map[Example::A], 0); }
impl<K: Internal<V>, V> EnumMap<K, V>[src]
impl<K: Internal<V>, V> EnumMap<K, V>ⓘImportant traits for Iter<'a, K, V>pub fn iter(&self) -> Iter<K, V>[src]
pub fn iter(&self) -> Iter<K, V>Returns an iterator over enum map.
ⓘImportant traits for IterMut<'a, K, V>pub fn iter_mut(&mut self) -> IterMut<K, V>[src]
pub fn iter_mut(&mut self) -> IterMut<K, V>Returns a mutable iterator over enum map.
pub fn len(&self) -> usize[src]
pub fn len(&self) -> usizeReturns number of elements in enum map.
pub fn is_empty(&self) -> bool[src]
pub fn is_empty(&self) -> boolReturns 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
#[macro_use] extern crate enum_map; use enum_map::EnumMap; #[derive(EnumMap)] enum Void {} #[derive(EnumMap)] 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]
pub fn swap(&mut self, a: K, b: K)Swaps two indexes.
Examples
#[macro_use] extern crate 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 values(&self) -> Iter<V>[src]
pub fn values(&self) -> Iter<V>An iterator visiting all values. The iterator type is &V.
Examples
#[macro_use] extern crate 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); }
pub fn as_slice(&self) -> &[V][src]
pub fn as_slice(&self) -> &[V]Converts an enum map to a slice representing values.
pub fn as_mut_slice(&mut self) -> &mut [V][src]
pub fn as_mut_slice(&mut self) -> &mut [V]Converts a mutable enum map to a mutable slice representing values.
pub fn values_mut(&mut self) -> IterMut<V>[src]
pub fn values_mut(&mut self) -> IterMut<V>An iterator visiting all values mutably. The iterator type is &mut V.
Examples
#[macro_use] extern crate 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); }
pub fn as_ptr(&self) -> *const V[src]
pub fn as_ptr(&self) -> *const VReturns a raw pointer to the enum map's buffer.
The caller must ensure that the slice outlives the pointer this function returns, or else it will end up pointing to garbage.
Modifying the container referenced by this slice may cause its buffer to be reallocated, which would also make any pointers to it invalid.
Examples
#[macro_use] extern crate enum_map; use 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]
pub fn as_mut_ptr(&mut self) -> *mut VReturns an unsafe mutable pointer to the enum map's buffer.
The caller must ensure that the slice outlives the pointer this function returns, or else it will end up pointing to garbage.
Modifying the container referenced by this slice may cause its buffer to be reallocated, which would also make any pointers to it invalid.
Examples
#[macro_use] extern crate enum_map; use 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: Internal<V> + Debug, V: Debug> Debug for EnumMap<K, V>[src]
impl<K: Internal<V> + Debug, V: Debug> Debug for EnumMap<K, V>fn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl<K: Internal<V>, V> Extend<(K, V)> for EnumMap<K, V>[src]
impl<K: Internal<V>, V> Extend<(K, V)> for EnumMap<K, V>fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)[src]
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)Extends a collection with the contents of an iterator. Read more
impl<'a, K, V> Extend<(&'a K, &'a V)> for EnumMap<K, V> where
K: Internal<V> + Copy,
V: Copy, [src]
impl<'a, K, V> Extend<(&'a K, &'a V)> for EnumMap<K, V> where
K: Internal<V> + Copy,
V: Copy, fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I)[src]
fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I)Extends a collection with the contents of an iterator. Read more
impl<K: Internal<V>, V> Index<K> for EnumMap<K, V>[src]
impl<K: Internal<V>, V> Index<K> for EnumMap<K, V>type Output = V
The returned type after indexing.
fn index(&self, key: K) -> &V[src]
fn index(&self, key: K) -> &VPerforms the indexing (container[index]) operation.
impl<K: Internal<V>, V> IndexMut<K> for EnumMap<K, V>[src]
impl<K: Internal<V>, V> IndexMut<K> for EnumMap<K, V>fn index_mut(&mut self, key: K) -> &mut V[src]
fn index_mut(&mut self, key: K) -> &mut VPerforms the mutable indexing (container[index]) operation.
impl<K: Internal<V>, V> Clone for EnumMap<K, V> where
K::Array: Clone, [src]
impl<K: Internal<V>, V> Clone for EnumMap<K, V> where
K::Array: Clone, fn clone(&self) -> Self[src]
fn clone(&self) -> SelfReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl<K: Internal<V>, V> Copy for EnumMap<K, V> where
K::Array: Copy, [src]
impl<K: Internal<V>, V> Copy for EnumMap<K, V> where
K::Array: Copy, impl<K: Internal<V>, V: PartialEq> PartialEq for EnumMap<K, V>[src]
impl<K: Internal<V>, V: PartialEq> PartialEq for EnumMap<K, V>fn eq(&self, other: &Self) -> bool[src]
fn eq(&self, other: &Self) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
fn ne(&self, other: &Rhs) -> boolThis method tests for !=.
impl<K: Internal<V>, V: Eq> Eq for EnumMap<K, V>[src]
impl<K: Internal<V>, V: Eq> Eq for EnumMap<K, V>impl<K: Internal<V>, V: Hash> Hash for EnumMap<K, V>[src]
impl<K: Internal<V>, V: Hash> Hash for EnumMap<K, V>fn hash<H: Hasher>(&self, state: &mut H)[src]
fn hash<H: Hasher>(&self, state: &mut H)Feeds this value into the given [Hasher]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, Feeds a slice of this type into the given [Hasher]. Read more
impl<K: Internal<V>, V: Default> Default for EnumMap<K, V>[src]
impl<K: Internal<V>, V: Default> Default for EnumMap<K, V>impl<'a, K: Internal<V>, V> IntoIterator for &'a EnumMap<K, V>[src]
impl<'a, K: Internal<V>, V> IntoIterator for &'a EnumMap<K, V>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]
fn into_iter(self) -> Self::IntoIterCreates an iterator from a value. Read more
impl<'a, K: Internal<V>, V> IntoIterator for &'a mut EnumMap<K, V>[src]
impl<'a, K: Internal<V>, V> IntoIterator for &'a mut EnumMap<K, V>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]
fn into_iter(self) -> Self::IntoIterCreates an iterator from a value. Read more
impl<K: Internal<V>, V> IntoIterator for EnumMap<K, V>[src]
impl<K: Internal<V>, V> IntoIterator for EnumMap<K, V>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]
fn into_iter(self) -> Self::IntoIterCreates an iterator from a value. Read more
impl<K: Internal<V> + Serialize, V: Serialize> Serialize for EnumMap<K, V>[src]
impl<K: Internal<V> + Serialize, V: Serialize> Serialize for EnumMap<K, V>Requires crate feature "serde"
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>[src]
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>Serialize this value into the given Serde serializer. Read more
impl<'de, K, V> Deserialize<'de> for EnumMap<K, V> where
K: Internal<V> + Internal<Option<V>> + Deserialize<'de>,
V: Deserialize<'de>, [src]
impl<'de, K, V> Deserialize<'de> for EnumMap<K, V> where
K: Internal<V> + Internal<Option<V>> + Deserialize<'de>,
V: Deserialize<'de>, Requires crate feature "serde"
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>[src]
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>Deserialize this value from the given Serde deserializer. Read more
impl<F: FnMut(K) -> V, K: Internal<V>, V> From<F> for EnumMap<K, V>[src]
impl<F: FnMut(K) -> V, K: Internal<V>, V> From<F> for EnumMap<K, V>