Skip to main content

deserialize

Function deserialize 

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

Deserialize a value from a singleton map.

This is the counterpart to serialize, deserializing from the singleton map format back to the original type.

ยงExamples

use noyalib::with::singleton_map;
use serde::{Deserialize, Serialize};

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

#[derive(Deserialize, Debug)]
struct Doc {
    #[serde(with = "singleton_map")]
    s: Status,
}

let d: Doc = noyalib::from_str("s:\n  Active: null\n").unwrap();
assert_eq!(d.s, Status::Active);