pub fn empty_string_as_none<'de, D, T>(de: D) -> Result<Option<T>, D::Error>
where
    D: Deserializer<'de>,
    T: Deserialize<'de>,
{
    let opt = Option::<String>::deserialize(de)?;
    match opt.as_deref() {
        None | Some("") => Ok(None),
        // If T = String, like in m.room.name, the second deserialize is actually superfluous.
        // TODO: optimize that somehow?
        Some(s) => T::deserialize(s.into_deserializer()).map(Some),
    }
}
/// 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(deserialize_with = "empty_string_as_none")]`
/// Relevant serde issue: <https://github.com/serde-rs/serde/issues/1425>
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(deserialize_with = "empty_string_as_none")]`
Relevant serde issue.
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 ( deserialize_with = " empty_string_as_none " ) ] ` Relevant serde issue .
pub fn empty_string_as_none<'de, D, T>(de: D) -> Result<Option<T>, D::Error>
where
    D: Deserializer<'de>,
    T: Deserialize<'de>,
{
    let opt = Option::<String>::deserialize(de)?;
    match opt.as_deref() {
        None | Some("") => Ok(None),
        // If T = String, like in m.room.name, the second deserialize is actually superfluous.
        // TODO: optimize that somehow?
        Some(s) => T::deserialize(s.into_deserializer()).map(Some),
    }
}
pub fn empty_string_as_none < ' de , D , T > ( de : D ) -> Result < Option < T > , D :: Error > where D : Deserializer < ' de > , T : Deserialize < ' de > , { let opt = Option :: < String > :: deserialize ( de ) ? ; match opt . as_deref ( ) { None | Some ( " " ) => Ok ( None ) , // If T = String, like in m.room.name, the second deserialize is actually superfluous. // TODO: optimize that somehow? Some ( s ) => T :: deserialize ( s . into_deserializer ( ) ) . map ( Some ) , } }
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."
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 . "
de
D