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
#[derive(PartialEq, Debug)]
pub struct Map<'a>(pub &'a [(String, String)]);

impl std::fmt::Display for Map<'_> {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        let arr: &[(String, String)] = self.0;
        write!(f, "{}: {}", arr[0].0, arr[0].1)?;
        for el in &arr[1..] {
            write!(f, "\n     {}: {}", el.0, el.1)?
        }
        Ok(())
    }
}

#[macro_export]
macro_rules! map {
    ($($key:ident $(: $value:expr)?),*) => {
        $crate::Map(&[
            $(map!(@map_one $key $(: $value)?)),*
        ][..])
    };

    (@map_one $key:ident) => {
        (stringify!($key).to_string(), $key.to_string())
    };
    (@map_one $key:ident : $value:expr) => {
        (stringify!($key).to_string(), $value.to_string())
    };
}