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

Document that len does not include skipped struct fields #2714

Merged
merged 1 commit into from
Mar 16, 2024

Conversation

Marcono1234
Copy link
Contributor

At least this seems to be how serde_derive behaves:

.map(|field| match field.attrs.skip_serializing_if() {
None => quote!(1),
Some(path) => {
let field_expr = get_member(params, field, &field.member);
quote!(if #path(#field_expr) { 0 } else { 1 })
}
})

Explicitly documenting this makes it easier for custom Serializer implementations to know what to expect from the len value, and makes it clearer for custom Serialize implementations to know what to provide as value.

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.

Thank you!

@dtolnay dtolnay merged commit 9f8c579 into serde-rs:master Mar 16, 2024
15 checks passed
@Marcono1234 Marcono1234 deleted the skipped-field-struct-len branch March 17, 2024 13:23
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