1#[macro_export]
2
3macro_rules! heroku_env {
4 ($($element: expr => $value: expr),* $(,)?) => {{
5 const SIZE: usize = ($crate::count![@COUNT; $($element),*]);
6 #[allow(unused_mut)]
7 let mut vs = ::std::collections::HashMap::with_capacity(SIZE);
8 $(vs.insert($element, $value);)*
9 vs
10 }};
11}
12
13#[macro_export]
14#[doc(hidden)]
15macro_rules! count {
16 (@COUNT; $($element:expr),*)=>{
17 <[()]>::len(&[$($crate::count![@SUBST; $element]),*])
18 };
19
20 (@SUBST; $_element:expr)=>{ () };
21}
22
23#[test]
24fn empty_map() {
25 use std::collections::HashMap;
26 let x: HashMap<&str, &str> = heroku_env![];
27 assert_eq!(true, x.is_empty())
28}
29
30#[test]
31fn trailing_comma() {
32 let _x = heroku_env!["a" => "b",];
33}
34
35#[test]
36fn one_element() {
37 let x = heroku_env!["foo" => "baz"];
38 assert_eq!(x.get("foo").unwrap(), &"baz");
39}
40
41#[test]
42fn multiple_elements() {
43 let x = heroku_env!["foo" => "baz", "a" => "b"];
44 assert_eq!(x.get("foo").unwrap(), &"baz");
45 assert_eq!(x.get("a").unwrap(), &"b");
46 assert_eq!(x.get("test3"), None);
47}
48
49#[allow(dead_code)]
50struct CompileFailTest;