Skip to main content

hmap_into

Macro hmap_into 

Source
hmap_into!() { /* proc-macro */ }
Expand description

Create a std::collections::HashMap, converting every key and value with Into::into.

The target types must be determined by the surrounding context, typically a type annotation. Each key is evaluated and converted before its value, and entries are processed once in input order. A later duplicate converted key replaces the earlier value. Empty maps and trailing commas are supported.

§Example

use helper::hmap_into;
use std::collections::HashMap;

let headers: HashMap<String, String> = hmap_into! {
    "Accept": "application/json",
    "User-Agent": String::from("helper"),
};
assert_eq!(headers["Accept"], "application/json");

Every entry requires a key and a value:

ⓘ
let _: std::collections::HashMap<String, String> = helper::hmap_into! {"key":};