Skip to content

Provide a `map!` macro that creates a new map collection then inserts key-value pairs.

Notifications You must be signed in to change notification settings

SixArm/map-rust-crate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

map! macro Rust crate

This crate provides the map! macro and related macros to create map collections, insert key-value pairs, and remove them. Inspired by vec!.

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 standard code:

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 standard code:

let mut m = HashMap::from([(1, 2), (3, 4)]);
m.remove(&1);
m.remove(&3);

About

Provide a `map!` macro that creates a new map collection then inserts key-value pairs.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages