logo
pub fn empty_string_as_none<'de, D, T>(de: D) -> Result<Option<T>, D::Error> where
    D: Deserializer<'de>,
    T: Deserialize<'de>, 
Expand description

Serde deserialization decorator to map empty Strings to None, and forward non-empty Strings to the Deserialize implementation for T. Useful for the typical “A room with an X event with an absent, null, or empty Y field should be treated the same as a room with no such event.” formulation in the spec.

To be used like this: #[serde(default, deserialize_with = "empty_string_as_none")] Relevant serde issue: https://github.com/serde-rs/serde/issues/1425