jamesmunns / postcard

A no_std + serde compatible message library for Rust
Apache License 2.0
930 stars 89 forks source link

Add support for skipped fields #174

Open dns2utf8 opened 2 months ago

dns2utf8 commented 2 months ago

Hi all

I made this PR to support maybe skipped fields, either always or dynamically with #[serde(skip_serializing_if = "Option::is_none")].

I have considered hiding the function behind a feature flag and adding a runtime Err without the flag so consumers of the crate notice that they were trying to serialize an object that would not be readable again.

Looking forward hearing from you, Stefan

PS: I assume that None::<()> takes the same amount of space as None::<u128> or something else would and that trick then allows us to stay with the wire format, 99% sure of that, happy to learn :blush:

netlify[bot] commented 2 months ago

Deploy Preview for cute-starship-2d9c9b canceled.

Name Link
Latest commit 8a4e39fbdc2ecde59b54d11f1bbd2e485a342ee7
Latest deploy log https://app.netlify.com/sites/cute-starship-2d9c9b/deploys/66e9ef813065fd000860938f
ManevilleF commented 1 month ago

Does this also fix the #[serde(skip)] attribute ? or is it only targetted to skip_serializing_if ?

dns2utf8-novaziun commented 1 month ago

It works with skip, but it serialized it to a None, so I am not sure what happens if your type is not Option<T>