1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#[macro_export]
macro_rules! testing_map {
    ($($k:expr => $v: expr),*,) => {{
        testing_map![$($k => $v),*]
    }};
    ($($k: expr => $v: expr),*) => {{
        use crate::testing::TestingType;
        use std::collections::hash_map::HashMap;

        // Variable definition is needed to ensure that the resulting type is known in the context
        #[allow(unused_mut)]
        let mut thing: HashMap<String, TestingType> = HashMap::default();
        $( let _ = thing.insert($k.to_string(), TestingType::from($v)); )*
        TestingType::from(thing)
    }};
}

#[macro_export]
macro_rules! testing_vec {
    ($($item: expr),*,) => {{
        testing_vec![$($item),*]
    }};
    ($($item: expr),*) => {{
        use crate::testing::TestingType;

        // Variable definition is needed to ensure that the resulting type is known in the context
        let thing: Vec<TestingType> = vec![
            $( TestingType::from($item), )*
        ];
        TestingType::from(thing)
    }};
}

#[cfg(feature = "trait_json")]
#[macro_export]
macro_rules! rust_json {
    ($($json:tt)+) => {{
        use serde_json;
        use json;
        let thing: json::JsonValue = json::parse(
            serde_json::to_string(&json![$($json)+]).unwrap().as_str(),
        ).unwrap();
        thing
    }};
}

#[cfg(feature = "trait_serde_yaml")]
#[macro_export]
macro_rules! yaml {
    ($($json:tt)+) => {{
        use serde_json;
        use serde_yaml;
        let thing: serde_yaml::Value = serde_yaml::from_str(
            serde_json::to_string(&json![$($json)+]).unwrap().as_str(),
        ).unwrap();
        thing
    }};
}