#insert #hash-map #macro

map

This crate provides the map! macro and map_insert! macro, to create a HashMap collection and insert key-value pairs. Inspired by the vec! macro.

4 stable releases

1.3.0 Nov 12, 2024
1.2.0 Nov 9, 2024
1.1.0 Nov 7, 2024
1.0.0 Nov 6, 2024

#671 in Rust patterns

Download history 308/week @ 2024-11-04 131/week @ 2024-11-11 19/week @ 2024-11-18 10/week @ 2024-11-25 7/week @ 2024-12-02 9/week @ 2024-12-09

53 downloads per month
Used in mailmerge

MIT OR Apache-2…

13KB
249 lines

map! macro Rust crate

This crate provides map! macros to create map collections and insert key-value pairs. This is inspired by the vec! macro.

map! macro

Create a new map collection and insert key-value pairs.

Example with tuple syntax:

let m = map!((1, 2), (3, 4));

Example with arrow syntax:

let m = map!(1 => 2, 3 => 4);

Equivalent Rust standard code:

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

map_insert! macro

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);

map_remove! macro

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

Example with tuple syntax:

let mut m = HashMap::from([(1, 2), (3, 4)]);
map_remove!(m, &1, &3);

Equivalent Rust std code with method remove:

let mut m = HashMap::from([(1, 2), (3, 4)]);
m.remove(&1);
m.remove(&3);

No runtime deps