trs_data_value/
utils.rs

1#[macro_export]
2macro_rules! stdhashmap {
3    (@single $($x:tt)*) => (());
4    (@count $($rest:expr),*) => (<[()]>::len(&[$($crate::stdhashmap!(@single $rest)),*]));
5
6    // case { "a" => 1, }
7    ($($key:expr => $value:expr,)+) => { $crate::stdhashmap!($($key => $value),+) };
8    // case { "a" => vec![1, 2, 3] }
9    ($($key:expr => vec![$($value:expr),*]),*) => {
10        $crate::stdhashmap!($($key => [$($value),*]),*)
11    };
12    // case { "a" => [1, 2, 3] }
13    ($($key:expr => [$($value:expr),*]),*) => {
14        {
15            let _cap = $crate::stdhashmap!(@count $($key),*);
16            let mut _map = ::std::collections::HashMap::with_capacity(_cap);
17            $(
18
19                let mut _arr = Vec::new();
20                $(
21                    _arr.push($value.into());
22                )*
23
24                    _map.insert($key.into(), _arr);
25            )*
26
27            _map
28        }
29    };
30    // case { "a" => 1 }
31    ($($key:expr => $value:expr),*) => {
32        {
33            let _cap = $crate::stdhashmap!(@count $($key),*);
34            let mut _map = ::std::collections::HashMap::with_capacity(_cap);
35            $(
36                _map.insert($key.into(), $value.into());
37            )*
38            _map
39        }
40    };
41}