bincode-org / bincode

A binary encoder / decoder implementation in Rust.
MIT License
2.63k stars 265 forks source link

falling test with serde::skip_serializing_if #713

Closed maks83 closed 1 month ago

maks83 commented 3 months ago
#[cfg(test)]
mod tests {
    #[derive(serde::Serialize, serde::Deserialize)]
    pub struct StructWithOption {
        #[serde(default, skip_serializing_if = "Option::is_none")]
        pub opt_field: Option<usize>,
    }

    #[test]
    fn struct_with_option() {
        let val = StructWithOption {
            opt_field: None,
        };

        let config = bincode::config::standard();
        let serialized = bincode::serde::encode_to_vec(&val, config).unwrap();
        bincode::serde::decode_from_slice::<StructWithOption, _>(&serialized[..], config).unwrap();
    }
}
VictorKoenders commented 3 months ago

Unfortunately this is an known issue in serde: https://github.com/serde-rs/serde/issues/1732

Not something we can fix in bincode

VictorKoenders commented 3 months ago

Unfortunately this is an known issue in serde: https://github.com/serde-rs/serde/issues/1732

This will be documented in bincode 2, but the following attributes are not compatible with bincode. These are all serde limitations.

stale[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.