Example scenario
struct Foo {
bar: Vec<i32>,
}
let foo = Foo { bar: vec![1, 2, 3] };
let bar: HashMap<i32, i32> = foo.bar.into_iter().map(|x|(x,x)).collect();
Expected behaviour: all values from foo.bar moved into new hash map, foo.bar now is clean vec and can be used after this, foo as whole struct can be used after this.
Real behaviour: foo.bar moved as whole collection, so whole struct foo now is partial moved and cant be used.
Question: why into_iter consume whole collection instead of consuming only elements and leave struct empty and how I can workaround this ?
New contributor
Kurai Akoraito is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.