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
// devela::examples::code::enumset
//
//! Shows how to use the [`enumset!`] declarative macro.
//!
//! # Examples
//!
//! This will create the [`EnumExample`] and [`EnumSetExample`] interrelated types.
//! ```
//! # use devela::enumset;
//! enumset! {
//! /// An example enum generated with [`enumset!`].
//! ///
//! /// It has an associated set [`EnumSetExample`].
//! #[allow(dead_code)]
//! #[derive(Clone)]
//! #[repr(u64)]
//! pub enum EnumExample<'a, 'b, T>(
//! /// An example set of enum variants, generated with [`enumset!`].
//! ///
//! /// Represents a set of [`EnumExample`] variants.
//! pub EnumSetExample: u8
//! )
//! [where T: Clone] // supports where clauses (between [])
//! {
//! /// A default unit variant.
//! Variant0 = 1,
//! /// A tuple variant.
//! Variant1([u8; 3]),
//! /// A self-referential tuple variant.
//! #[cfg(feature = "std")]
//! Variant2(Box<Self>),
//! /// A struct variant with discriminant.
//! Variant3 {
//! /// field1 docs.
//! some: [u8; 2],
//! /// field2 docs.
//! other: u32
//! } = 30,
//! /// Supports generics and lifetimes.
//! Variant4(T, &'a str, &'b u32),
//! }
//! impl enum
//! /// Classification helpers for [`EnumExample`].
//! {
//! /// Returns whether this variant belongs to [`EnumSetExample::DATA`].
//! pub const fn is_data(&self) -> bool {
//! self.is_in(EnumSetExample::DATA)
//! }
//! }
//! impl enum
//! /// Small associated constants for [`EnumExample`].
//! #[allow(missing_docs)]
//! {
//! pub const HAS_CUSTOM_IMPLS: bool = true;
//! }
//! impl set
//! /// Named subsets.
//! {
//! /// Variants carrying payload data.
//! pub const DATA: Self = Self::all().without(Self::Variant0);
//!
//! /// Variants that can hold either borrowed or allocated data.
//! pub const BORROW_OR_ALLOC: Self = {
//! #[allow(unused_mut)]
//! let mut v = Self::Variant4;
//! #[cfg(feature = "std")]
//! v.insert(Self::Variant2);
//! v
//! };
//! }
//! }
//! impl<T: Clone> Default for EnumExample<'_, '_, T> {
//! /// Returns [`EnumExample::Variant0`].
//! fn default() -> Self {
//! Self::Variant0
//! }
//! }
//!
//! assert_eq![5, EnumExample::<()>::VARIANTS];
//! ```
//
use enumset;
enumset!