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

Allow C-like enum with a repr other than u8 to be Encode/Decode #255

Open
real-felix opened this issue Feb 25, 2021 · 1 comment
Open

Allow C-like enum with a repr other than u8 to be Encode/Decode #255

real-felix opened this issue Feb 25, 2021 · 1 comment

Comments

@real-felix
Copy link

Hi, currently this code cannot compile:

#[derive(Clone, Copy, Debug, Decode, Encode, PartialEq)]
#[repr(u16)]
pub enum Status {
    Foo = 100,
    Bar = 200,
    Baz = 300,
}

Error message:

error: literal out of range for `u8`
  --> frame/foo/src/lib.rs
   |
   |     Baz = 300,
   |           ^^^
   |
   = note: the literal `300` does not fit into the type `u8` whose range is `0..=255`

It's because, as per the documentation,

The variable is encoded with one byte for the variant

but is there a reason to make this rule stands for the C-like enum?

@bkchr bkchr transferred this issue from paritytech/substrate Feb 25, 2021
@bkchr
Copy link
Member

bkchr commented Feb 25, 2021

For now, I just propose that you write the Decode/Encode impl manually. Isn't that hard.

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

2 participants