-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
negative explicit variant discriminator not allowed in enums #592
Comments
It looks like serde encodes the variants as their index, not as the actual value: #[derive(serde::Serialize)]
enum Foo {
A = -1,
}
fn main() {
println!("{:?}", bincode::serialize(&Foo::A))
} Prints out Unfortunately we have to remain backwards compatible with bincode 1.3.3 so the change is that we should encode it as the variant index, not the value of the variant. If you're willing to make this PR that would be appreciated! |
I was looking at |
Yes, I believe the current implementation encodes enum variants as their values. They need to be encoded as their index enum Foo {
Bar = 5, // needs to be encoded as 0u32
} |
From #537 (comment):
It appears that enum discriminators are encoded as
u32
, and changing this toi32
will change the byte encoding of positive discriminators as well.I've done some work on a patch for this if this is a desirable change.
The text was updated successfully, but these errors were encountered: