macro_rules! map {
() => { ... };
($($key:expr => $val:expr),* $(,)?) => { ... };
}Expand description
Creates a Map containing the given key-value pairs.
This macro provides a convenient way to initialize a Map with known entries.
It comes in two forms:
§Forms
map!()- Creates an empty mapmap!(key => value, ...)- Creates a map with the specified key-value pairs
§Examples
// Create an empty map
let empty = map!();
// Create a map with initial values
let m = map! {
"name" => "Alice",
"age" => 30,
"active" => true,
};§Notes
- Keys are used directly without conversion
- Values are converted using
.into()to support flexible value types - The map is pre-allocated with the exact capacity needed
- Trailing commas are allowed