Skip to main content

map_insert

Macro map_insert 

Source
macro_rules! map_insert {
    ($map:ident, $(( $k:expr, $v:expr )),* $(,)?) => { ... };
    ($map:ident, $( $k:expr => $v:expr ),* $(,)?) => { ... };
}
Expand description

Use an existing map collection and insert key-value pairs.

Example with tuple syntax:

let mut m = HashMap::new();
map_insert!(m, (1, 2), (3, 4));

Example with arrow syntax:

let mut m = HashMap::new();
map_insert!(m, 1 => 2, 3 => 4);

Equivalent Rust std code with method insert:

let mut m = HashMap::new();
m.insert(1, 2);
m.insert(3, 4);