4 stable releases
new 1.3.0 | Nov 12, 2024 |
---|---|
1.2.0 | Nov 9, 2024 |
1.1.0 | Nov 7, 2024 |
1.0.0 | Nov 6, 2024 |
#541 in Rust patterns
435 downloads per month
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);