bubble_bath/macros.rs
1/// Handy macro to construct a hashmap
2///
3/// Example:
4///
5/// ```rust
6/// # use bubble_bath::hashmap;
7/// # use std::collections::HashMap;
8/// let _: HashMap<_, HashMap<_, _>> = hashmap! [
9/// "key" => hashmap![],
10/// "key2" => hashmap![
11/// "inner key" => "inner value",
12/// ],
13/// ];
14/// ```
15#[macro_export]
16macro_rules! hashmap {
17 ($($key:expr => $value:expr),*$(,)?) => {{
18 let mut hashmap = ::std::collections::HashMap::default();
19
20 $(
21 let _ = hashmap.insert($key, $value);
22 )*
23
24 hashmap
25 }}
26}
27
28/// Handy macro to construct a hashset
29///
30/// Example:
31///
32/// ```rust
33/// # use bubble_bath::hashset;
34/// # use std::collections::HashSet;
35/// let _ : HashSet<_> = hashset![
36/// "key1",
37/// "key2",
38/// "key3",
39/// ];
40#[macro_export]
41macro_rules! hashset {
42 ($($value:expr),*$(,)?) => {{
43 let mut hashset = ::std::collections::HashSet::default();
44
45 $(
46 let _ = hashset.insert($value);
47 )*
48
49 hashset
50 }}
51}