Macro smallmap::smallmap

source ·
macro_rules! smallmap {
    () => { ... };
    ($({$key:expr => $value:expr}),* $(,)?) => { ... };
}
Expand description

A helper macro for creating Map instances with or without pre-set entries.

Create empty map

With no parameters this just calls Map::new().

let map: Map<i32, i32> = smallmap!();
let map2: Map<i32, i32> = Map::new();
assert_eq!(map, map2);

Create with key-value pairs

You can specify some entries to pre-insert in the format {key => value}.

let map = smallmap! {
  {"Key" => 1},
  {"Key two" => 2},
  {"Key three" => 3},
  {"Key four" => 4},
};