Skip to main content

deserialize

Function deserialize 

Source
pub fn deserialize<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
where T: DeserializeOwned + 'static, D: Deserializer<'de>,
Expand description

Deserialize an optional value from a singleton map.

This is the counterpart to serialize, deserializing from the singleton map format back to Option<T>.

ยงExamples

use noyalib::with::singleton_map_optional;

#[derive(serde::Deserialize, serde::Serialize, PartialEq, Debug)]
enum Status { Active }

#[derive(serde::Deserialize, Debug)]
struct Doc {
    #[serde(with = "singleton_map_optional", default)]
    s: Option<Status>,
}

let d: Doc = noyalib::from_str("s: ~\n").unwrap();
assert!(d.s.is_none());