[−][src]Macro mapcomp::hashmapc
Hash Map Comprehension
Creates a HashMap
from the contents of the comprehension. It is
analogous to Python's dictionary comprehension except that it uses the =>
token instead of a colon.
Python code:
numbers = [6, 4, 18]
halves = {str(x): x / 2 for x in numbers}
Rust equivalent code:
let numbers = [6, 4, 18]; let halves = hashmapc!{x.to_string() => x / 2; for x in numbers.iter()}; for &(k, v) in &[("6", 3), ("4", 2), ("18", 9)] { assert_eq!(halves[k], v); }