macro_rules! nested_singleton_map_deserialize {
    ($yaml:expr) => { ... };
}
Expand description

A macro that deserializes a nested singleton map from a YAML format.

This macro uses the serde_yml crate to deserialize the input value from a YAML string. It directly calls serde_yml::from_str to perform the deserialization and uses expect to handle any potential deserialization errors by panicking with a provided message.

§Example

use serde::{Deserialize, Serialize};
use serde_yml::nested_singleton_map_deserialize;
use serde_yml;

// Define your enums and structs as usual
#[derive(Serialize, Deserialize, PartialEq, Debug)]
enum InnerEnum {
    Variant1,
    Variant2(String),
}

#[derive(Serialize, Deserialize, PartialEq, Debug)]
enum OuterEnum {
    Variant1(InnerEnum),
    Variant2 {
        inner: InnerEnum,
    },
}

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Example {
    #[serde(with = "serde_yml::with::nested_singleton_map")]
    field: OuterEnum,
}

// Create a YAML string to deserialize
let yaml = r#"
    field:
      Variant2:
        inner:
          Variant2: value
"#;

// Use the macro to deserialize the YAML string
let example: Example = nested_singleton_map_deserialize!(&yaml);

// Verify the deserialization result
let expected = Example {
    field: OuterEnum::Variant2 {
        inner: InnerEnum::Variant2("value".to_string()),
    },
};
assert_eq!(example, expected);