Skip to content

Add support for serde(skip) #14

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

Merged
merged 5 commits into from
Jun 4, 2025
Merged

Conversation

sosthene-nitrokey
Copy link
Contributor

skip causes the index to not be increased to match deserialization from upstream serde.

@AlfioEmanueleFresta
Copy link
Contributor

@robin-nitrokey, @sosthene-nitrokey, could this be merged? It would help us address linux-credentials/libwebauthn#74. TIA!

@robin-nitrokey
Copy link
Member

Generally yes, but I’m not sure how we should handle indexing with skipped fields. Not incrementing the index for a skipped field makes sense, but it would silently change the serialization format so we would need to be very careful when upgrading.

Alternatively, we could move to explicit indices (#17).

@AlfioEmanueleFresta Do you have a preference regarding the index?

@AlfioEmanueleFresta
Copy link
Contributor

Thanks @robin-nitrokey! I agree explicit indexing sounds like the best option.

Our use case is to skip unused indexes in CTAP spec models (eg. see linux-credentials/libwebauthn#74), so either incrementing the index automatically, or explicit indexing, would be needed.

@robin-nitrokey
Copy link
Member

Okay. I think we could release a v0.1.2 that implements skip while incrementing the index and then release a v0.2.0 that splits the derive macro into SerdeIndexed with explicit indexing and SerdeAutoIndexed with the current behavior. @sosthene-nitrokey What do you think?

AlfioEmanueleFresta added a commit to linux-credentials/libwebauthn that referenced this pull request Feb 17, 2025
…75)

Fixes #74, causing an error with `change_pin_hid` with Solo2 keys. 

Unconditional skips aren't supported by `serde-indexed` - this includes
either `serde(skip_serializing)` and `serde(skip)`.

This change works around the limitation by using `skip_serializing_if`
alongside a method which returns always true.

Long term fix is trussed-dev/serde-indexed#14
(unmerged since Feb 2024) - pinged authors and contributors to see if
this can be merged.
@sosthene-nitrokey
Copy link
Contributor Author

sosthene-nitrokey commented Feb 17, 2025

That sounds good! I would also merge all the other PRs for 0.1.2.

Also note that once serde adds support for #[serde(rename = 123)] (see here for the PR adding support for that in enums) serde-indexed will probably be deprecated. But that PR has been opened for a while.

src/parse.rs Outdated
Comment on lines 149 to 151
if !matches!(skip_serializing_if, Skip::Always) {
idx += 1;
}
Copy link
Member

Choose a reason for hiding this comment

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

Per the discussion in this thread, we should increment the index even if the field is skipped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add an option to be able to not increment. (Default would be to increment).

src/parse.rs Outdated
Comment on lines 19 to 23
pub enum Skip {
None,
If(syn::ExprPath),
Always,
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub enum Skip {
None,
If(syn::ExprPath),
Always,
}
pub enum Skip {
Never,
If(syn::ExprPath),
Always,
}

Skip::None could also be read as skip None values.

@robin-nitrokey robin-nitrokey merged commit 432a7a2 into trussed-dev:main Jun 4, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants