Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have exhaustive subenums #36

Open
deoqc opened this issue Aug 9, 2024 · 0 comments
Open

Have exhaustive subenums #36

deoqc opened this issue Aug 9, 2024 · 0 comments

Comments

@deoqc
Copy link

deoqc commented Aug 9, 2024

Hello and thanks for the great library.

Most of the times that I use, I have something like:

#[subenum(Edible, NonEdible)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Plant {
    #[subenum(Edible)]
    Basil,
    #[subenum(Edible)]
    Tomato,
   #[subenum(NonEdible)]
    Manzanita,
   #[subenum(NonEdible)]
    Pine,
}

Then I manually implement a type:

pub enum EdibleGroup {
   Edible(PlantEdible),
   NonEdible(PlantNonEdible),
}

// also have defined the PlantEdible and PlanNonEdible enums

And finally I can have ìmpl From<EdibleGroup> for Plant and ìmpl From<Plant> for EdibleGroup.

Is it a feature that you would consider to have builtin? The design would be something like:

 #[subenum(EdibleGroup(Edible, NonEdible))]
...

I use the term exhaustive because each case must have 1 and only 1 of these Edible and NonEdible or it will error compile time.

And I would implement and send a pull request. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant