@@ -79,10 +79,6 @@ enum Enum { /* ... */ }
79
79
> }
80
80
> ```
81
81
82
- ### `#[derive(AsVariant )]`
83
-
84
- The `AsVariant ` derive macro requires the variant 's field type to implement `Clone `.
85
-
86
82
## Macro helper attributes
87
83
88
84
Most of the derive macros support helper attributes :
@@ -91,7 +87,7 @@ Most of the derive macros support helper attributes:
91
87
92
88
#### `#[enumcapsulate(exclude(…))]`
93
89
94
- Exclude this variant from trait derivation .
90
+ Selectively opt out of ` enumcapsulate ` trait derivations .
95
91
96
92
- `#[enumcapsulate(exclude(…))]`
97
93
@@ -127,6 +123,24 @@ Exclude this variant from trait derivation.
127
123
128
124
Exclude variant from specific `enumcapsulate` derive macros.
129
125
126
+ > [! IMPORTANT ]
127
+ > This attribute is recognized by the following variant- based derive macros:
128
+ >
129
+ > - `AsVariant `
130
+ > - `AsVariantMut `
131
+ > - `AsVariantRef `
132
+ > - `FromVariant `
133
+ > - `IntoVariant `
134
+ > - `From `
135
+ > - `TryInto `
136
+ >
137
+ > … as well as the umbrella derive macro :
138
+ >
139
+ > - `Encapsulate `
140
+
141
+ If you wish to opt out of a select few of `Encapsulate `'s trait derives,
142
+ then you can do so by use of an `#[enumcapsulate(exclude(…))]` attribute:
143
+
130
144
```rust
131
145
#[derive(Encapsulate )]
132
146
enum Enum {
@@ -143,20 +157,6 @@ enum Enum {
143
157
}
144
158
```
145
159
146
- This attribute is recognized by the following variant- based derive macros:
147
-
148
- - `AsVariant `
149
- - `AsVariantMut `
150
- - `AsVariantRef `
151
- - `FromVariant `
152
- - `IntoVariant `
153
- - `From `
154
- - `TryInto `
155
-
156
- … as well as the umbrella derive macro :
157
-
158
- - `Encapsulate `
159
-
160
160
#### `#[enumcapsulate(field(… = …)]`
161
161
162
162
Select a specific variant field as target for trait derivation.
@@ -169,6 +169,21 @@ Select a specific variant field as target for trait derivation.
169
169
170
170
Select field with name `<name>` to be used as target.
171
171
172
+ > [! IMPORTANT ]
173
+ > This attribute is recognized by the following variant- based derive macros:
174
+ >
175
+ > - `AsVariant `
176
+ > - `AsVariantMut `
177
+ > - `AsVariantRef `
178
+ > - `FromVariant `
179
+ > - `IntoVariant `
180
+ > - `From `
181
+ > - `TryInto `
182
+ >
183
+ > … as well as the umbrella derive macro :
184
+ >
185
+ > - `Encapsulate `
186
+
172
187
```rust
173
188
#[derive(Encapsulate )]
174
189
enum Enum {
@@ -188,19 +203,47 @@ enum Enum {
188
203
>
189
204
> Alternatively the variant can be excluded via `#[enumcapsulate(exclude)]`.
190
205
191
- This attribute is recognized by the following variant- based derive macros:
206
+ ##### `#[enumcapsulate(discriminant(value = …))]`
207
+
208
+ Specify a memory representation for the generated discriminant type .
209
+
210
+ > [! IMPORTANT ]
211
+ > This attribute is only recognized by the `VariantDiscriminant ` derive macro .
212
+
213
+ If you wish to specify a custom memory representation for the discriminant
214
+ type generated by the `VariantDiscriminant ` derive macro , then you can
215
+ do so by use of an `#[enumcapsulate(discriminant(value = <expr>))]` attribute:
192
216
193
- - `AsVariant `
194
- - `AsVariantMut `
195
- - `AsVariantRef `
196
- - `FromVariant `
197
- - `IntoVariant `
198
- - `From `
199
- - `TryInto `
217
+ ```rust
218
+ #[derive(VariantDiscriminant )]
219
+ enum Enum {
220
+ #[enumcapsulate(discriminant(value = 42))]
221
+ VariantA (i32 ),
222
+
223
+ VariantB { b: u32 },
224
+ }
225
+ ```
200
226
201
- … as well as the umbrella derive macro :
227
+ ##### `#[enumcapsulate(discriminant(name = …))]`
202
228
203
- - `Encapsulate `
229
+ Specify a custom name for the generated discriminant type .
230
+
231
+ > [! IMPORTANT ]
232
+ > This attribute is only recognized by the `VariantDiscriminant ` derive macro .
233
+
234
+ If you wish to specify a custom name for the discriminant type
235
+ generated by the `VariantDiscriminant ` derive macro , then you can do
236
+ so by use of an `#[enumcapsulate(discriminant(name = …))]` attribute:
237
+
238
+ ```rust
239
+ #[derive(VariantDiscriminant )]
240
+ enum Enum {
241
+ #[enumcapsulate(discriminant(name = CustomDiscriminant ))]
242
+ VariantA (i32 ),
243
+
244
+ VariantB { b: u32 },
245
+ }
246
+ ```
204
247
205
248
## Generics
206
249
0 commit comments