Crates.io | map |
lib.rs | map |
version | 1.3.0 |
source | src |
created_at | 2024-11-06 18:59:37.234721 |
updated_at | 2024-11-12 17:55:21.122725 |
description | 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. |
homepage | |
repository | https://github.com/sixarm/map-macro-rust-crate/ |
max_upload_size | |
id | 1438691 |
size | 12,357 |
This crate provides map!
macros to create map collections and
insert key-value pairs. This is inspired by the vec!
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);
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);
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);