Skip to main content

map

Macro map 

Source
macro_rules! map {
    {} => { ... };
    { owned: $($key:expr_2021 => $value:expr_2021),+ $(,)? } => { ... };
    { $($key:expr_2021 => $value:expr_2021),+ $(,)? } => { ... };
}
Available on crate features alloc and std only.
Expand description

Creates a HashMap from key-value pairs. Available with the std feature.

The owned: form calls to_owned() on each key and value.

use collections::map;

let map = map! { 1 => "one", 2 => "two" };
assert_eq!(map.len(), 2);
let owned = map! { owned: "key" => "value" };
assert_eq!(owned["key"], "value");