Skip to content

Commit f9613fe

Browse files
committed
Update and improve documentation with respect to the Encapsulate derive macro
1 parent 88bc74c commit f9613fe

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Please make sure to add your changes to the appropriate categories:
2626

2727
- Bumped MSRV from "1.74.0" to "1.78.0".
2828
- Made the enum-level `#[enumcapsulate(exclude(…))]` helper macros only have an effect on derives, when orchestrated through the `Encapsulate` derive macro.
29+
- Made `Encapsulate` derive macro no longer derive `VariantDiscriminant`.
2930

3031
### Deprecated
3132

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,30 @@ Safe casting for newtype enums and their variants.
1313

1414
The `enumcapsulate` crate exports the following traits:
1515

16-
| Traits | Functionality |
17-
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18-
| `AsVariant` | Provides owned access to the current variant's field. |
19-
| `AsVariantMut` | Provides mutable borrowed access to the current variant's field. |
20-
| `AsVariantRef` | Provides borrowed access to the current variant's field. |
21-
| `Encapsulate` | Umbrella derive macro for `AsVariant`, `AsVariantMut`, `AsVariantRef`, `From`, `FromVariant`, `IntoVariant`, `TryInto`, `VariantDiscriminant`, and `VariantDowncast` |
22-
| `FromVariant` | Creates an instance of `Self` from the unambiguous field type of one of its variants. |
23-
| `IntoVariant` | Returns the current variant's field, consuming `self`. |
24-
| `VariantDiscriminant` | Used to obtain an enum variant's discriminant |
25-
| `VariantDowncast` | Convenience umbrella trait utilizing `AsVariant`, `AsVariantRef`, `AsVariantMut`, and `IntoVariant` |
16+
| Traits | Functionality |
17+
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
18+
| `Encapsulate` | Umbrella derive macro for `AsVariant`, `AsVariantMut`, `AsVariantRef`, `From`, `FromVariant`, `IntoVariant`, `TryInto`, and `VariantDowncast`. |
19+
| `FromVariant` | Creates an instance of `Self` from the unambiguous field type of one of its variants. |
20+
| `IntoVariant` | Returns the current variant's field, consuming `self`. |
21+
| `AsVariant` | Provides owned access to the current variant's field. |
22+
| `AsVariantMut` | Provides mutable borrowed access to the current variant's field. |
23+
| `AsVariantRef` | Provides borrowed access to the current variant's field. |
24+
| `VariantDowncast` | Convenience umbrella trait utilizing `AsVariant`, `AsVariantRef`, `AsVariantMut`, and `IntoVariant`. |
25+
| `VariantDiscriminant` | Used to obtain an enum variant's discriminant. |
2626

2727
## Derive macros
2828

2929
The `enumcapsulate` crate exports the following corresponding derive macros, if the `"derive"` feature is enabled (which is the default):
3030

31-
- `AsVariant`
32-
- `AsVariantMut`
33-
- `AsVariantRef`
3431
- `Encapsulate`
3532
- `From`
33+
- `TryInto`
3634
- `FromVariant`
37-
- `IntoVariant`- `TryInto`
35+
- `IntoVariant`
36+
- `AsVariant`
37+
- `AsVariantMut`
38+
- `AsVariantRef`
39+
- `VariantDowncast`
3840
- `VariantDiscriminant`
3941

4042
## Documentation

macros/README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ Derive macros for [enumcapsulate](https://crates.io/crates/enumcapsulate) crate.
1313

1414
The `enumcapsulate-macros` proc-macro crate exports the following derive macros:
1515

16-
| Derive macro | Functionality |
17-
| --------------------- | -------------------------------------------------------------------------------------------- |
18-
| `FromVariant` | Derives impls for `Self: enumcapsulate::FromVariant<T>` for each non-unit variant type `T`. |
19-
| `IntoVariant` | Derives impls for `Self: enumcapsulate::FromVariant<T>` for each non-unit variant type `T`. |
20-
| `From` | Derives impls for `Self: core::convert::From<T>` for each non-unit variant type `T`. |
21-
| `TryInto` | Derives impls for `T: core::convert::TryFrom<Self>` for each non-unit variant type `T`. |
22-
| `AsVariant` | Derives impls for `Self: enumcapsulate::AsVariant<T>` for each non-unit variant type `T`. |
23-
| `AsVariantMut` | Derives impls for `Self: enumcapsulate::AsVariantMut<T>` for each non-unit variant type `T`. |
24-
| `AsVariantRef` | Derives impls for `Self: enumcapsulate::AsVariantRef<T>` for each non-unit variant type `T`. |
25-
| `VariantDiscriminant` | Derives impl for `Self: enumcapsulate::VariantDiscriminant`. |
26-
27-
… as well as an umbrella derive macro `Encapsulate`.
16+
| Derive macro | Functionality |
17+
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
18+
| `Encapsulate` | Derives impls for `AsVariant`, `AsVariantMut`, `AsVariantRef`, `From`, `FromVariant`, `IntoVariant`, `TryInto`, and `VariantDowncast`. |
19+
| `FromVariant` | Derives impls for `Self: enumcapsulate::FromVariant<T>` for each non-unit variant type `T`. |
20+
| `IntoVariant` | Derives impls for `Self: enumcapsulate::FromVariant<T>` for each non-unit variant type `T`. |
21+
| `From` | Derives impls for `Self: core::convert::From<T>` for each non-unit variant type `T`. |
22+
| `TryInto` | Derives impls for `T: core::convert::TryFrom<Self>` for each non-unit variant type `T`. |
23+
| `AsVariant` | Derives impls for `Self: enumcapsulate::AsVariant<T>` for each non-unit variant type `T`. |
24+
| `AsVariantMut` | Derives impls for `Self: enumcapsulate::AsVariantMut<T>` for each non-unit variant type `T`. |
25+
| `AsVariantRef` | Derives impls for `Self: enumcapsulate::AsVariantRef<T>` for each non-unit variant type `T`. |
26+
| `VariantDowncast` | Derives impl for `Self: enumcapsulate::VariantDowncast`. |
27+
| `VariantDiscriminant` | Derives impl for `Self: enumcapsulate::VariantDiscriminant`. |
2828

2929
> [!NOTE]
3030
> The implementations generated by the `From` and `FromVariant`, as well as the `TryInto` and `IntoVariant` derive macro pairs are semantically equivalent.
3131
3232
### `#[derive(Encapsulate)]`
3333

34-
The umbrella derive macro `Encapsulate` allows for conveniently deriving `AsVariant`, `AsVariantMut`, `AsVariantRef`, `From`, `FromVariant`, `IntoVariant`, `TryInto`, `VariantDiscriminant`, and `VariantDowncast` all at once.
34+
The umbrella derive macro `Encapsulate` allows for conveniently deriving `AsVariant`, `AsVariantMut`, `AsVariantRef`, `From`, `FromVariant`, `IntoVariant`, `TryInto`, and `VariantDowncast` all at once.
3535

3636
The following two snippets are semantically equivalent:
3737

@@ -42,14 +42,14 @@ enum Enum { /* ... */ }
4242

4343
```rust
4444
#[derive(
45-
FromVariant,
46-
IntoVariant,
4745
From,
4846
TryInto,
47+
FromVariant,
48+
IntoVariant,
4949
AsVariant,
5050
AsVariantMut,
5151
AsVariantRef,
52-
VariantDiscriminant,
52+
VariantDowncast,
5353
)]
5454
enum Enum { /* ... */ }
5555
```
@@ -96,7 +96,7 @@ Exclude this variant from trait derivation.
9696
9797
- `#[enumcapsulate(exclude(…))]`
9898
99-
Exclude variant from specific `enumcapsulate` derive macros.
99+
Exclude variant from specific `Encapsulate` derive macros.
100100
101101
> [!IMPORTANT]
102102
> This attribute is only recognized by the `Encapsulate` umbrella derive macro.

macros/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ pub fn derive_variant_discriminant(input: TokenStream) -> TokenStream {
385385
/// AsVariantMut,
386386
/// AsVariantRef,
387387
/// VariantDowncast,
388-
/// VariantDiscriminant,
389388
/// )]
390389
/// enum Enum {
391390
/// // ...

0 commit comments

Comments
 (0)