Crates.io | map |
lib.rs | map |
version | 1.2.0 |
source | src |
created_at | 2024-11-06 18:59:37.234721 |
updated_at | 2024-11-09 12:15:47.944951 |
description | This crate provides the `map!` macro `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 | 10,761 |
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);
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);
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);