-
-
Notifications
You must be signed in to change notification settings - Fork 275
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
Handle skip_serializing_if #387
Comments
I don't think we'd want this as a default feature, as it will be a breaking change in the binary format of existing data. However we could add this to the Options trait (e.g. |
Oh that would be neat. |
This would definitely have helped me recently; I have a large struct that was originally made for JSON, so I use Could |
I don't think its possible to handle #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
struct Foo {
#[serde(skip_serializing_if = "test_fn")]
foo: Option<u8>,
#[serde(skip_serializing_if = "test_fn")]
bar: Option<u8>,
}
fn test_fn(x: &Option<u8>) -> bool { x.is_none() } If only one of the fields gets skipped, on deserialize we have no way to know which field was skipped. |
The above code will panic because of serde-rs/serde#1732. I do have a proposal to fix it on the serde side (serde-rs/serde#2012), but I haven't gotten confirmation they want it yet.
A way to fix this on the bincode side would be to start calling
serialize_len
for structs as well. This would be a breaking change on the format; I'm not sure if that's possible in bincode.It would also impact the size of every bincode'd struct, which might not be desired.
The text was updated successfully, but these errors were encountered: