subenum
subenum copied to clipboard
Feature request: permit subenum to be "unit-only"
It would be nice to be able to extract just the variants from an enum as a sub-enum, ignoring tuple-like or struct-like data. So this:
#[repr(u32)]
#[subenum(Variants(unit_like))]
enum Foo {
#[subenum(Variants)]
SomeTuple(i32, String) = 37,
#[subenum(Variants)]
SomeStruct{
data: String,
} = 42,
}
...would generate something like this:
#[repr(u32)]
enum Variants {
SomeTuple = 37,
SomeStruct = 42,
}
impl TryFrom<Foo> for Variants {
...
}
Of course, Foo could not impl From<Variants> unless all the inner data implemented Default, and even then it might be preferable to have a more explicit impl Variants { pub fn as_foo_with_defaults(self) -> Foo { ... } }.
Does strum cover your use case?
https://docs.rs/strum/latest/strum/derive.EnumDiscriminants.html
Oops, sorry, I forgot to respond. Yes, it does; thanks!