1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/// 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
///
/// ```rust
/// 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");
/// ```
;
}