subenum icon indicating copy to clipboard operation
subenum copied to clipboard

Have exhaustive subenums

Open deoqc opened this issue 6 months ago • 0 comments

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.

deoqc avatar Aug 09 '24 12:08 deoqc