You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: macros/README.md
+91Lines changed: 91 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -291,6 +291,97 @@ This attribute is recognized by the following variant-based derive macros:
291
291
292
292
- `Encapsulate`
293
293
294
+
## Generics
295
+
296
+
There is limited support for generic enums:
297
+
298
+
Variants using generic const/type parameters are always excluded when deriving generic traits with `enumcapsulate`'s derive macros.
299
+
300
+
The reason for this behavior is that implementing generic traits for variants that use any of the generic parameters of the enum tends to result in conflicting implementations inRust, as shown by the following example program:
301
+
302
+
```rust
303
+
useenumcapsulate::FromVariant;
304
+
305
+
pubstructVariantA;
306
+
pubstructVariantB;
307
+
308
+
#[derive(FromVariant)]
309
+
// error[E0119]: conflicting implementations of trait `FromVariant<VariantB>` for type `Enum<VariantB>`
So in order to avoid such pitfalls altogether `enumcapsulate`'s derive macros will skip `impl<T> FromVariant<T> for Enum<T>`, since it uses a generic type (or const) parameter of `Enum<T>`.
354
+
355
+
So all you have to do is provide your own non-generic implementations for specific type instances of your generic type yourself, filling any gaps left behind by the derive macro:
0 commit comments