Macro string_literals::string_hashmap

source ·
macro_rules! string_hashmap {
    () => { ... };
    ($($k:expr => $v:expr),+ $(,)?) => { ... };
}
Expand description

Create a HashMap of HashMap<String, String> with string literals

This macro also allows zero arguments (an empty hash map). In this case however, it would be shorter in length to call HashMap::new().

§Examples

Empty hash maps:

use std::collections::HashMap;
use string_literals::string_hashmap;

let map: HashMap<String, String> = string_hashmap!{};
assert!(map.is_empty());

Non-empty hash maps:

use std::collections::HashMap;
use string_literals::string_hashmap;

let map: HashMap<String, String> = string_hashmap!{
    "Banana" => "Good",
    "Apple" => "Okay",
};
assert_eq!(map[&"Banana".to_owned()], "Good".to_owned());
assert_eq!(map[&"Apple".to_owned()], "Okay".to_owned());