Macro enum_map::enum_map [−][src]
macro_rules! enum_map {
{ $($t : tt) * } => { ... };
}
Expand description
Enum map constructor.
This macro allows to create a new enum map in a type safe way. It takes
a list of ,
separated pairs separated by =>
. Left side is |
separated list of enum keys, or _
to match all unmatched enum keys,
while right side is a value.
The iteration order when using this macro is not guaranteed to be consistent. Future releases of this crate may change it, and this is not considered to be a breaking change.
Examples
use enum_map::{enum_map, Enum};
#[derive(Enum)]
enum Example {
A,
B,
C,
D,
}
let enum_map = enum_map! {
Example::A | Example::B => 1,
Example::C => 2,
_ => 3,
};
assert_eq!(enum_map[Example::A], 1);
assert_eq!(enum_map[Example::B], 1);
assert_eq!(enum_map[Example::C], 2);
assert_eq!(enum_map[Example::D], 3);