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

Internally tagged tuple and newtype variants #2884

Open
axos88 opened this issue Jan 19, 2025 · 1 comment
Open

Internally tagged tuple and newtype variants #2884

axos88 opened this issue Jan 19, 2025 · 1 comment

Comments

@axos88
Copy link

axos88 commented Jan 19, 2025

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.

@axos88
Copy link
Author

axos88 commented Jan 19, 2025

Perhaps use the already existing rename directive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant