Is there a way to force the algebraic type of an associated type of e.g. a trait:
trait Foo {
type Thingamabob; // <- this shall be an enum, any enum, but never a struct.
}
I think that the rust type system currently cannot express this, but maybe someone knows a cool trick I didn't think of.
One could use a derive macro, which is only derivable for enums as a marker, but I don't want to force the user to put #[derive(Enum)] on all their enums.
Out of sheer curiosity, but what is your exact use case for this? enum's themselves are tagged union's, which themselves can be substituted for a custom struct with an ad-hoc discriminator in a few cases. Why would you want to allow only the former, at the expense of everything else?
It was more of a late-night thought on whether one could do this.
I don't have a current real-world use case that would need such a feature.
It's more about understanding the possibilities of the language in more detail and to push the edges of what's currently possible.
I explored the trait-and-derive solution last night, but I am not satisfied with it:
Due to the fact that derive macros need their own crate, I cannot currently properly seal the underlying internal traits, so a user could still falsely struct S; impl Enum for S {} which I generally want to avoid.