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

EnumDiscriminants should inherit the repr of the enum they are derived from #283

Closed
jscatena88 opened this issue Jul 10, 2023 · 1 comment · Fixed by #288
Closed

EnumDiscriminants should inherit the repr of the enum they are derived from #283

jscatena88 opened this issue Jul 10, 2023 · 1 comment · Fixed by #288

Comments

@jscatena88
Copy link
Contributor

The below example code will generate VehicleDiscriminants enum with Car and Truck variants but it will be repr(usize) instead of inheriting the u8 repr of Vehicle additionally they will have the default enum representations (Car = 0 and Vehicle = 1 in this case)

// Custom discriminant tests
#[derive(EnumDiscriminants, Debug, PartialEq)]
#[strum_discriminants(derive(FromRepr))]
#[repr(u8)]
enum Vehicle {
    Car(CarModel) = 1,
    Truck(TruckModel) = 3,
}

I would have expected the above code to produce the following:

#[repr(u8)]
#[derive(FromRepr)]
enum VehicleDiscriminants {
    Car = 1,
    Truck = 3,
}
@Peternator7
Copy link
Owner

It's a breaking change, but I agree it's certainly more inline with what would be expected. Happy to take a PR if you're interested.

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

Successfully merging a pull request may close this issue.

2 participants