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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
///
/// ## `#[mune(bitflags = <name_format: string>)]`
///
/// **Available only on unsigned numeric `#[repr]`s apart from `usize`.**
///
/// Generates associated bitflag constants for every variant in the enum using a `1 << i` shift
/// pattern. `<name_format>` must be a string literal containing a single `{}` placeholder to format
/// the names of the generated constants. The type of each constant will be the same as the `#[repr]`
/// of the enum
///
/// **Note:** The `{}` placeholder will be replaced with the name of each variant converted to
/// `SCREAMING_SNAKE_CASE` as per the [rust style guide](https://doc.rust-lang.org/style-guide/advice.html#names).
/// The conversion is done using [`heck::ToShoutySnakeCase`]
///
/// # 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);
/// ```
///
/// ```
/// #[pm2::mune(bitflags = "FLAG_{}")]
/// #[repr(u8)]
/// enum ModifierKey {
/// Control,
/// Alt,
/// LeftShift,
/// RightShift,
/// Meta,
/// }
///
/// assert_eq!(ModifierKey::FLAG_CONTROL, 1);
/// assert_eq!(ModifierKey::FLAG_ALT, 2);
/// assert_eq!(ModifierKey::FLAG_LEFT_SHIFT, 4);
/// assert_eq!(ModifierKey::FLAG_RIGHT_SHIFT, 8);
/// assert_eq!(ModifierKey::FLAG_META, 16);
/// ```