Iteration with .iter()
gives temporary references. If you want the elements by value, then you need to dereference or clone them, or use .into_iter()
instead.
vec.iter.copied.map
vec.iter.cloned.map
vec.iter.map
vec.iter.map
vec.into_iter.map
BTW: &
in closure arguments may seem backwards, because that's a pattern, not a type. The syntax for args is |pattern:type|
.
See how it works with for … in
in the Rust Playground.