macro_rules! map_comp { (@__ for $($vars:pat),+ in $iter:expr; $($recurse:tt)+) => { ... }; (@__ for $($vars:pat),+ in $iter:expr => $keymap:expr, $valmap:expr $(, if $guard:expr)? $(,)?) => { ... }; (for $($t:tt)+) => { ... }; }
Expand description
Performs a special comprehension that returns a HashMap. This is
different from the other comprehensions in that it requires two expressions:
one for the key and one for the value. For more exhaustive documentation
and usage examples, see vec_comp!.
Example
Mapping last names to first names:
let names = vec![("John", "Smith"), ("Jane", "Doe"), ("Bob", "Smith")];
let m = map_comp! {for (first, last) in names => last, first, if last == "Smith"};