An alternative to enum variants types

I've wanted enum-variant-as-a-nameable-type for a while (I have an issue comment somewhere…). I have some probing questions that should hopefully help flesh out this idea :slight_smile: .

  • How is name lookup done on the right side? Must it be MyEnum - { MyEnum::A }? What if it was MyEnum - { MyEnum::None } (where the name would be potentially ambiguous otherwise)? (This goes back to this previous thread.)
  • What is Option - { Some, None }? It should be a Never-like type (unless the type is #[non_exhaustive] I suppose).
  • Given type MySmallerEnum = MyEnum - { MyEnum::A };, is MySmallerEnum - { MyEnum::A } valid? How about MySmallerEnum::C (or must it still be MyEnum::C)?
  • Can this stack? Given type MyOtherSmallerEnum = MyEnum - { MyEnum::C };, is MySmallerEnum - MyOtherSmallerEnum possible? If so, is it the same type as MyEnum - { MyEnum::A, MyEnum::C } or are they distinct? If distinct, do I need a .into() for each "type subtraction" layer to get to the original?
  • Is u8 - { 0 } equivalent to NonZero<u8>?
  • What is the interaction with #[non_exhaustive]?

Anyways, related prior work:

1 Like