iterator borrow error when filtering a vec of structs
Trying to do something simple: filter a Vec<Item> by a field, then map to another type. I wrote:
let out = items.iter().filter(|i| i.active).map(|i| &i.name).collect::<Vec<_>>();
and then I later mutate items and still want to use out. Compiler complains that items is borrowed as immutable. I thought the collect would end the borrow. How long does the borrow from an iterator actually last?
4 replies