Support for enum with reference variants
Hi,
First of all, I'd like to thank you for this amazing library! It really makes code much cleaner by avoiding this repeating pattern!
I recently came across a use case that I'm not sure how I should handle.
If I have some trait VariantCommon I want to implement for both a Variant but also for a reference to a variant, e.g.:
#[enum_dispatch]
enum Variant{
TypeAName(TypeA),
TypeBName(TypeB),
}
#[enum_dispatch]
enum VariantRef<'a>{
TypeAName(&'a TypeA),
TypeBName(&'a TypeB),
}
#[enum_dispatch(Variant,VariantRef)]
trait VariantCommon {}
How can I do this? I tried to use PhantomData but the problem persists as I still need to reimplement the trait for that wrapping structure even if &'a TypeA and TypeA have exactly the same implementation, i.e. :
struct TypeARef<'a>(PhantomData<&'a TypeA>);
struct TypeBRef<'a>(PhantomData<&'a TypeB>);
#[enum_dispatch]
enum VariantRef<'a>{
TypeAName(TypeARef<'a>),
TypeBName(TypeBRef<'a>),
}
This will result in a the trait VariantCommon is not implemented for TypeARef<'_> which makes complete sense, but kinda destroys the whole intent of not repeating the implementation.
Is there a workaround to achieve what I'm looking for? Also, I know I could implement VariantCommon for &TypeA but this again will result in duplication or my own macro to generate the duplicate implementation.
Best,
Philippe