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

Feature request: permit subenum to be "unit-only" #40

Open
BatmanAoD opened this issue Oct 22, 2024 · 0 comments
Open

Feature request: permit subenum to be "unit-only" #40

BatmanAoD opened this issue Oct 22, 2024 · 0 comments

Comments

@BatmanAoD
Copy link

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 { ... } }.

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