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

Allow #[serde(default)] on tuple structs #2553

Merged
merged 1 commit into from Aug 6, 2023

Conversation

Mingun
Copy link
Contributor

@Mingun Mingun commented Aug 3, 2023

Right now you cannot place #[serde(default)] at tuple struct, although it is possible to mark individual fields as #[serde(default)]:

#[derive(Deserialize)]
struct Tuple(
  // possible, but make no sense in that case, because if
  // field will be set to default value that means that sequence
  // is exhausted and the next field will fail to deserialize
  #[serde(default)] u8,
  u8,
);
#[derive(Deserialize)]
#[serde(default)] // impossible, but make sense
struct Tuple(
  #[serde(default)] u8,
  u8,
);

This PR fixes that and also guaranties that tuple structs will always have a trail of defaulted non-skipped fields as soon as first defaulted field is appear.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay dtolnay merged commit 7393169 into serde-rs:master Aug 6, 2023
16 checks passed
@Mingun Mingun deleted the default-on-tuples branch August 6, 2023 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants