Skip to content

Nested enums do not generate the same output as serde #147

Description

@FallingSnow

Copied from #140 (comment).

I tried using ts-rs in combination with nanoserde but ran into some differences in format. Given a snippet of the code where I'm trying to generate and send a Message.

pub enum Message {
    Input(InputEvent)
}

pub enum InputEvent {
    Mouse(MouseEvent),
    Keyboard(ButtonEvent),
}

pub enum MouseEvent {
    Button(ButtonEvent),
    Scroll(ScrollEvent),
    Move(MoveEvent),
}

pub struct MoveEvent {
    pub type_: MovementType,
    pub x: i32,
    pub y: i32,
}

ts-rs generates what I would expect:

{"Input":{"Mouse":{"Move":{"type_":"Absolute","x":1918,"y":616}}}}

But nanoserde expects (notice the extra array nesting):

{"Input":[{"Mouse":[{"Move":[{"type_":"Absolute","x":0,"y":0}]}]}]}

I also gave serde/serde_json a try and ended up with the expected output:

{"Input":{"Mouse":{"Move":{"type_":"Absolute","x":0,"y":0}}}}

Therefore I am unable to use nanoserde and ts-rs together.

Is it intended that nanoserde do this extra array wrapping?

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