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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use ;
/// Extend enums to provide additional functionality
///
/// # Added constants
///
/// ## <code>REPR: [Option]<&[str]></code>
///
/// The type declared in `#[repr]` if present, as a string
///
/// ## <code>NUM_VARIANTS: [usize]</code>
///
/// The number of variants in the enum
///
/// ## `FIRST_VARIANT: Self`
///
/// The first variant as defined in source order
///
/// ## `LAST_VARIANT: Self`
///
/// The last variant as defined in source order
///
/// ## `MAX_DISCRIMINANT: <repr>`
///
/// **Available only on numeric `#[repr]`s.**
///
/// The highest numerical discriminant value among all variants. The type is the same as the
/// `#[repr]` of the enum
///
/// # Features
///
/// ## `#[mune(deref_discriminant)]`
///
/// **Available only on numeric `#[repr]`s.**
///
/// Implements [`Deref`][::core::ops::Deref] with a [`Target`][::core::ops::Deref::Target] of the
/// `#[repr]` of the enum allowing you to simply do `*MyEnum::Variant` to get the value of the
/// discriminant
///
/// # Limitations
///
/// * Generic parameters and `where` clauses are currently unsupported
/// * Only unit enums are supported for now, and without explicit discriminants
/// * Only `#[repr]`s with the type are supported
///
/// # Examples
///
/// ```
/// #[pm2::mune]
/// #[derive(Debug, PartialEq)]
/// enum MyEnum {
/// A,
/// B,
/// C,
/// D,
/// }
///
/// assert_eq!(MyEnum::REPR, None);
/// assert_eq!(MyEnum::NUM_VARIANTS, 4);
/// assert_eq!(MyEnum::FIRST_VARIANT, MyEnum::A);
/// assert_eq!(MyEnum::LAST_VARIANT, MyEnum::D);
/// ```
///
/// ```
/// #[pm2::mune]
/// #[repr(u8)]
/// #[derive(Debug, PartialEq)]
/// enum MyEnum {
/// A,
/// B,
/// C,
/// D,
/// }
///
/// assert_eq!(MyEnum::REPR, Some("u8"));
/// ```
///
/// ```
/// #[pm2::mune(deref_discriminant)]
/// #[repr(u8)]
/// #[derive(Debug, PartialEq)]
/// enum MyEnum {
/// A,
/// B,
/// C,
/// D,
/// }
///
/// let a: u8 = *MyEnum::A;
/// assert_eq!(a, 0);
///
/// assert_eq!(*MyEnum::B, 1);
/// assert_eq!(*MyEnum::C, 2);
/// assert_eq!(*MyEnum::D, 3);
/// ```