Skip to main content

deserialize

Function deserialize 

pub fn deserialize<'de, T, D>(
    deserializer: D,
) -> Result<Option<T>, <D as Deserializer<'de>>::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;
use serde::{Deserialize, Serialize};

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

#[derive(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());