I have three structs:
struct A; struct B; struct C { a: Option<A>, b: Option<B> } Given inputs Vec<A> and Vec<B> and some predicate function, I want to create an output Vec<C>, which is a combination of the elements of the inputs, something like the following:
let aVec: Vec<A> = vec![]; let bVec: Vec<B> = vec![]; let mut cVec: Vec<C> = vec![]; for a in aVec { if let Some(b) = bVec.into_iter().find(predicate) { cVec.push(C{a: Some(a), b: Some(b)}); } } Is there a way to do this without needing B to be copyable? Both input vectors aren't required after the operation. Also, is this possible without the loop?