Skip to content

Internally tagged tuple and newtype variants #2884

Open
@axos88

Description

@axos88

What is the exact issues on supporting internally tagged enums for all cases (newtypes of all types (ha!), tuple variants, etc)

I would guess in case of the tuple variants in the default case the challenge is where to put the data.

I would propose two solutions:

  • fall back to adjacent tagging in cases that are not supported by internal tagging (the easier solution)
  • allow the user to "name" the tuple members, like so:
#[derive(Serialize, Deserialize)]
#[serde(tag = variant )]
enum Foo {
  Tuple( #[serde(key = bar)] Bar, #[serde(key = baz)] Baz),
  Newtype( #[serde(key = value )] u32)
}

This would serialize to yaml like so:

data:
  - variant: Tuple
    bar: ....
    baz: .....
  - variant: Newtype
    value: 42

The latter would basically allow newtype/struct variants to be serialized/ deserialuzes as struct variants.

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