map

Crates.iomap
lib.rsmap
version1.3.0
sourcesrc
created_at2024-11-06 18:59:37.234721
updated_at2024-11-12 17:55:21.122725
descriptionThis 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
repositoryhttps://github.com/sixarm/map-macro-rust-crate/
max_upload_size
id1438691
size12,357
Joel Parker Henderson (joelparkerhenderson)

documentation

README

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);
Commit count: 0

cargo fmt