Skip to content

derive Support for primitive enums #3

@ryan-summers

Description

@ryan-summers

It would be beneficial to be able to derive Encode and Decode for primitive enums (C-like enums) with a specified repr:

#[derive(Encode, Decode)]
#[repr(u8)]
enum States {
    Starting = 0,
    Idle = 1,
    Active = 2,
}

Currently, the derive only works for structs and internally panics on simple enums.

There's some difficulties here:

  1. Complex enums could theoretically be supported by treating internal enum data as a struct, but this starts getting into the land of "how do we specify exactly how data should be laid out"
  2. What happens if the user doesn't specify a repr? Do we default to e.g. u32?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions