dhashmap

Macro dhashmap 

Source
macro_rules! dhashmap {
    () => { ... };
    ($($key1:expr, $key2:expr => $value:expr),+ $(,)?) => { ... };
    ($(($key1:expr, $key2:expr) => $value:expr),+ $(,)?) => { ... };
}
Expand description

Create a DHashMap<K1, K2, V, RandomState> from a list of sequentially given keys and values.

Input data list must follow one of these rules:

  • K1, K2 => V, K1, K2 => V … and so on;
  • (K1, K2) => V, (K1, K2) => V … and so on.

Last comma separator can be omitted. If this macros is called without arguments, i.e. like

let map: DHashMap<i32, String, String>  = dhashmap![];

it is equivalent to DHashMap::new() function

§Examples

use double_map::{DHashMap, dhashmap};

// Calling macros without arguments is equivalent to DHashMap::new() function
let _map0: DHashMap<i32, i32, i32> = dhashmap![];

let map = dhashmap!{
    1, "a" => "One",
    2, "b" => "Two", // last comma separator can be omitted
};

assert_eq!(map.get_key1(&1),   Some(&"One"));
assert_eq!(map.get_key1(&2),   Some(&"Two"));
assert_eq!(map.get_key2(&"a"), Some(&"One"));
assert_eq!(map.get_key2(&"b"), Some(&"Two"));

let map2 = dhashmap!{
    (3, "c") => "Three",
    (4, "d") => "Four" // last comma separator can be omitted
};

assert_eq!(map2.get_key1(&3),   Some(&"Three"));
assert_eq!(map2.get_key1(&4),   Some(&"Four"));
assert_eq!(map2.get_key2(&"c"), Some(&"Three"));
assert_eq!(map2.get_key2(&"d"), Some(&"Four"));