pub struct EnumTable<'a, K, V>where
    K: Enumerated,
    V: Default,
{ /* private fields */ }
Expand description

A key-value table optimized for Enums used as keys. Initialized with V’s Default values.

use enum_collections::{EnumTable, Enumerated};
#[derive(Enumerated)]
enum Letter {
    A,
    B,
}

let mut map: EnumTable<Letter, u8> = EnumTable::new();
map[Letter::A] = 42;
assert_eq!(42u8, map[Letter::A]);
assert_eq!(u8::default(), map[Letter::B]);

Using get and insert functions.

use enum_collections::{enum_collections, EnumTable, Enumerated};
#[derive(Enumerated)]
enum Letter {
    A,
    B,
}

let mut map: EnumTable<Letter, u8> = EnumTable::new();
map.insert(Letter::A, 42);
assert_eq!(&42u8, map.get(Letter::A));
assert_eq!(&u8::default(), map.get(Letter::B));

Implementations§

Creates a new EnumTable, with pre-allocated space for all keys of the enum K. With the underlying array righsized, no resizing is further required. All values are initialized with V’s Default value.

Obtain a value for given key, always returning a value V, as the EnumTable is pre-initialized with defaults.

Args
  • key - Instance of K, used to look up the corresponding value.

Stores given value under the provided key. Overrides any existing corresponding value.

Args
  • key - The instance of K the value inserted can be looked up for.
  • values - Value to bind to K.

Resets value of type V corresponding to key to its default by calling its Default trait implementation.

Args
  • key - The instance of K pointing at the slot to reset to default.

Trait Implementations§

Constructs a new instance, capable of holding all values of key K without further resizing.

The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.