Python-style collection comprehensions in Rust

The structure is consistent with Python's list and dictionary comprehensions.

Comprehensions consist of a body followed by a for ... in ... expression, followed by any combination of for ... in ... or if ... expressions.

The for ... in ... and if ... expressions are nested left-to-right, so rust c!(do_something(x, y); for x in 0..10 if x % 2 == 1 for y in 'a'..='z');

is equivalent to:

rust for x in 0..10 { if x % 2 == 1 { for y in 'a'..='z' { do_something(x, y); } } }

Examples

Vectors

[2, 6, 12, 20, 30, 42, 56, 72, 90, 110]

Hash Maps

Statements