Struct enum_collections::EnumTable
source · 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::{enum_collections, EnumTable, Enumerated};
#[enum_collections]
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};
#[enum_collections]
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§
source§impl<'a, K, V> EnumTable<'a, K, V>where
K: Enumerated,
V: Default,
impl<'a, K, V> EnumTable<'a, K, V>where
K: Enumerated,
V: Default,
sourcepub fn get(&self, key: K) -> &V
pub fn get(&self, key: K) -> &V
Obtain a value for given key, always returning a value V,
as the EnumTable is pre-initialized with defaults.
Args
key- Instance ofK, used to look up the corresponding value.