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)] from enum_map_derive crate.

Examples

extern crate enum_map;
#[macro_use]
extern crate enum_map_derive;

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> EnumMap<K, V>
[src]

Returns an iterator over enum map.

impl<K: Internal<V>, V: Default> EnumMap<K, V> where
    K::Array: Default
[src]

Creates an enum map with default values.

extern crate enum_map;
#[macro_use]
extern crate enum_map_derive;

use enum_map::EnumMap;

#[derive(EnumMap)]
enum Example {
    A,
}

fn main() {
    let enum_map = EnumMap::<_, i32>::new();
    assert_eq!(enum_map[Example::A], 0);
}

Trait Implementations

impl<F: Fn(K) -> V, K: Internal<V>, V> From<F> for EnumMap<K, V>
[src]

Performs the conversion.

impl<K: Internal<V>, V> Clone for EnumMap<K, V> where
    K::Array: Clone
[src]

Returns a copy of the value. Read more

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> PartialEq for EnumMap<K, V> where
    K::Array: PartialEq
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<K: Internal<V>, V> Eq for EnumMap<K, V> where
    K::Array: Eq
[src]

impl<K: Internal<V>, V> Hash for EnumMap<K, V> where
    K::Array: Hash
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<K: Internal<V>, V> Default for EnumMap<K, V> where
    K::Array: Default
[src]

Returns the "default value" for a type. Read more

impl<K: Internal<V>, V> Index<K> for EnumMap<K, V>
[src]

The returned type after indexing

The method for the indexing (container[index]) operation

impl<K: Internal<V>, V> IndexMut<K> for EnumMap<K, V>
[src]

The method for the mutable indexing (container[index]) operation

impl<'a, K: Internal<V>, V> IntoIterator for &'a EnumMap<K, V>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more