[−][src]Macro mapcomp::vecc
Vector Comprehension
Creates a new Vec
from the contents of the comprehension. Vector
comprehensions are analogous to Python's list comprehension.
Python code:
items = [4, 7, 2]
even_squares = [x*x for x in items if x % 2 == 0]
Rust equivalent code:
let items = [4, 7, 2]; let even_squares = vecc![x*x; for x in &items; if x % 2 == 0]; assert_eq!(even_squares, vec![16, 4]);