Skip to content

Commit 4bb6149

Browse files
committed
Add documentation sections for the #[enumcapsulate(discriminant(…))] attributes
1 parent a30623a commit 4bb6149

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

macros/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,40 @@ then you can do so by use of an `#[enumcapsulate(exclude(…))]` attribute:
105105
enum Enum { /* ... */ }
106106
```
107107
108+
##### `#[enumcapsulate(discriminant(repr = …))]`
109+
110+
Specify a memory representation for the generated discriminant type.
111+
112+
> [!IMPORTANT]
113+
> This attribute is only recognized by the `VariantDiscriminant` derive macro.
114+
115+
If you wish to specify a custom memory representation for the discriminant
116+
type generated by the `VariantDiscriminant` derive macro, then you can
117+
do so by use of an `#[enumcapsulate(discriminant(repr = <typename>))]` attribute:
118+
119+
```rust
120+
#[derive(VariantDiscriminant)]
121+
#[enumcapsulate(discriminant(repr = u8))]
122+
enum MyEnum { /* ... */ }
123+
```
124+
125+
##### `#[enumcapsulate(discriminant(name = …))]`
126+
127+
Specify a custom name for the generated discriminant type.
128+
129+
> [!IMPORTANT]
130+
> This attribute is only recognized by the `VariantDiscriminant` derive macro.
131+
132+
If you wish to specify a custom name for the discriminant type
133+
generated by the `VariantDiscriminant` derive macro, then you can do
134+
so by use of an `#[enumcapsulate(discriminant(name = <typename>))]` attribute:
135+
136+
```rust
137+
#[derive(VariantDiscriminant)]
138+
#[enumcapsulate(discriminant(name = MyDiscriminant))]
139+
enum MyEnum { /* ... */ }
140+
```
141+
108142
### Variant attributes
109143
110144
> [!NOTE]
@@ -245,6 +279,48 @@ enum Enum {
245279
}
246280
```
247281
282+
##### `#[enumcapsulate(discriminant(value = …))]`
283+
284+
Specify a memory representation for the generated discriminant type.
285+
286+
> [!IMPORTANT]
287+
> This attribute is only recognized by the `VariantDiscriminant` derive macro.
288+
289+
If you wish to specify a custom memory representation for the discriminant
290+
type generated by the `VariantDiscriminant` derive macro, then you can
291+
do so by use of an `#[enumcapsulate(discriminant(value = <expr>))]` attribute:
292+
293+
```rust
294+
#[derive(VariantDiscriminant)]
295+
enum Enum {
296+
#[enumcapsulate(discriminant(value = 42))]
297+
VariantA(i32),
298+
299+
VariantB { b: u32 },
300+
}
301+
```
302+
303+
##### `#[enumcapsulate(discriminant(name = …))]`
304+
305+
Specify a custom name for the generated discriminant type.
306+
307+
> [!IMPORTANT]
308+
> This attribute is only recognized by the `VariantDiscriminant` derive macro.
309+
310+
If you wish to specify a custom name for the discriminant type
311+
generated by the `VariantDiscriminant` derive macro, then you can do
312+
so by use of an `#[enumcapsulate(discriminant(name = …))]` attribute:
313+
314+
```rust
315+
#[derive(VariantDiscriminant)]
316+
enum Enum {
317+
#[enumcapsulate(discriminant(name = CustomDiscriminant))]
318+
VariantA(i32),
319+
320+
VariantB { b: u32 },
321+
}
322+
```
323+
248324
## Generics
249325
250326
There is limited support for generic enums:

0 commit comments

Comments
 (0)