map

Crates.iomap
lib.rsmap
version1.2.0
sourcesrc
created_at2024-11-06 18:59:37.234721
updated_at2024-11-09 12:15:47.944951
descriptionThis crate provides the `map!` macro `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
size10,761
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);

Example with multiple lines and tuple syntax:

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

Example with multiple lines and 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);

Example with multiple lines and tuple syntax:

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

Example with multiple lines and 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);
Commit count: 0

cargo fmt