easy_log/
map.rs

1#[derive(PartialEq, Debug)]
2pub struct Map<'a>(pub &'a [(String, String)]);
3
4impl std::fmt::Display for Map<'_> {
5    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
6        let arr: &[(String, String)] = self.0;
7        write!(f, "{}: {}", arr[0].0, arr[0].1)?;
8        for el in &arr[1..] {
9            write!(f, "\n     {}: {}", el.0, el.1)?
10        }
11        Ok(())
12    }
13}
14
15#[macro_export]
16macro_rules! map {
17    ($($key:ident $(: $value:expr)?),*) => {
18        $crate::Map(&[
19            $(map!(@map_one $key $(: $value)?)),*
20        ][..])
21    };
22
23    (@map_one $key:ident) => {
24        (stringify!($key).to_string(), $key.to_string())
25    };
26    (@map_one $key:ident : $value:expr) => {
27        (stringify!($key).to_string(), $value.to_string())
28    };
29}