Skip to content

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

Open
@real-felix

Description

@real-felix

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions