Skip to content

Commit a30623a

Browse files
committed
Clean up "README.md" file of enumcapsulate-macros crate
1 parent 26b95df commit a30623a

File tree

1 file changed

+72
-29
lines changed

1 file changed

+72
-29
lines changed

macros/README.md

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ enum Enum { /* ... */ }
7979
> }
8080
> ```
8181
82-
### `#[derive(AsVariant)]`
83-
84-
The `AsVariant` derive macro requires the variant's field type to implement `Clone`.
85-
8682
## Macro helper attributes
8783
8884
Most of the derive macros support helper attributes:
@@ -91,7 +87,7 @@ Most of the derive macros support helper attributes:
9187
9288
#### `#[enumcapsulate(exclude(…))]`
9389
94-
Exclude this variant from trait derivation.
90+
Selectively opt out of `enumcapsulate` trait derivations.
9591
9692
- `#[enumcapsulate(exclude(…))]`
9793
@@ -127,6 +123,24 @@ Exclude this variant from trait derivation.
127123
128124
Exclude variant from specific `enumcapsulate` derive macros.
129125
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+
130144
```rust
131145
#[derive(Encapsulate)]
132146
enum Enum {
@@ -143,20 +157,6 @@ enum Enum {
143157
}
144158
```
145159
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-
160160
#### `#[enumcapsulate(field(… = …)]`
161161
162162
Select a specific variant field as target for trait derivation.
@@ -169,6 +169,21 @@ Select a specific variant field as target for trait derivation.
169169
170170
Select field with name `<name>` to be used as target.
171171
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+
172187
```rust
173188
#[derive(Encapsulate)]
174189
enum Enum {
@@ -188,19 +203,47 @@ enum Enum {
188203
>
189204
> Alternatively the variant can be excluded via `#[enumcapsulate(exclude)]`.
190205
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:
192216
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+
```
200226
201-
as well as the umbrella derive macro:
227+
##### `#[enumcapsulate(discriminant(name = …))]`
202228
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+
```
204247
205248
## Generics
206249

0 commit comments

Comments
 (0)