juniper/juniper_graphql_transport_ws/src/utils.rs

10 lines
262 B
Rust
Raw Normal View History

use serde::{Deserialize, Deserializer};
pub(crate) fn default_for_null<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de> + Default,
{
Ok(Option::<T>::deserialize(deserializer)?.unwrap_or_default())
}