Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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(enum): u16/u32 discriminants #315
feat(enum): u16/u32 discriminants #315
Changes from 3 commits
dca2e53
24a3be1
784755f
8914f06
557e240
4b6cb92
df34e73
0c2b17e
58b8b14
910bb08
de5f32f
3da00ce
4acaec2
affadf4
aef4b2e
5389767
bb457c7
8e1a8b2
6f67b47
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
also, this behaviour should be controlled by borsh-specific item attribute, say
#[borsh(enum_repr = "i16")]
,not by
repr
, which is used to control memory layout in program, which is, strictly speaking, independent of how it's serialized for later transfer or saving to disk (which is what serialization is usually used for).Say, an enum may not have
#[repr(u16)]
and have all discriminants withingu8
range, but still have#[borsh(enum_repr = "u16")]
and use 2 bytes for tag serialization.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.
Assuming we have borsh enum_repr, how should borsh handle this
?
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.
may use
u16
instead of"u16"
? may just doborsh(rerp=
instead of #[borsh(enum_repr` because it is on enum anyway?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.
may it be like this?
and fail compile same way
#repr
fails because u8 was set (so borsh rerp interpreted types same way/algorithm) as native repr.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.
looks good,
repr
should then check it annotates an enum item.well, one would've to change 1u8 to 1 to compile with borsh attribute.
Specifying
Q = -10
would allow annotating with#[repr(i8)]
and#[borsh(repr = i16)]
at the same timeThere 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.
Still, maybe naming it
enum_tag
will be better, rust'srepr
has other subattributes, not related to enums at all