-
Notifications
You must be signed in to change notification settings - Fork 78
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
feat!: ser/de enum discriminant #138
feat!: ser/de enum discriminant #138
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@encody Thanks for the PR! Is it blocking you now, should I cut the release ASAP?
@frol It is not blocking, just a matter of convenience. |
Unless I’m misunderstanding something, this sounds like a terrible idea since users have no way to opt out of this change. Anyone who used borsh for enums which included variants with specified value is now unable to upgrade. This should have been done as a derive annotation, such as |
@mina86 Having a mismatch between the enum discriminant value and borsh serialized value could have silently led people to wrong assumptions. It is indeed a limitation that you cannot opt out, but why would you really? What is the use-case when you want the enum discriminant value not to match the borsh-discriminant? |
The way to resolve it is to remove the explicit values assigned to the enum variants on the borsh-serialized enum and create a separate enum with the explicitly specified enum values. Overall, I agree that it is unfortunate that explicit values were not taken into account from the beginning, and now we face this breaking change. |
The use case is an existing code base with an enum where this is the case. It doesn’t matter if it makes sense. It’s also possible that authors of such code base would have preferred behaviour from this PR, but that wasn’t the behaviour so now to maintain compatibility they have to stick to the old behaviour.
Part of the problem is that this is now a silent failure. The code will compile just fine and only break in production. If upgrading to newest borsh broke compilation in places where doing so would break compatibility this would be a different matter. |
@mina86 I am happy to hear your suggestions and review PRs. Unfortunately, there are no active contributors to borsh :-( |
This is a breaking change, since it will now serialize some enums (those that have manually specified discriminants) differently.