macro_rules! et {
($variant:ty, $value:ty, |$variable:ident| $($tt:tt)*) => { ... };
}Expand description
Builds an EnumTable for $variant and $value inside a const block.
The closure body must be valid in a const context; passing a non-const
expression is a compile error. For a runtime equivalent, use
crate::EnumTable::from_fn, crate::EnumTable::try_from_fn, or
crate::EnumTable::checked_from_fn instead.
ยงExamples
use enum_table::{EnumTable, Enumerable, et};
#[derive(Enumerable, Copy, Clone)]
enum Test {
A,
B,
C,
}
const TABLE: EnumTable<Test, &'static str, { Test::COUNT }> =
et!(Test, &'static str, |t| match t {
Test::A => "A",
Test::B => "B",
Test::C => "C",
});
assert_eq!(TABLE.get(Test::A), &"A");
assert_eq!(TABLE.get(Test::B), &"B");
assert_eq!(TABLE.get(Test::C), &"C");