I have the following code:
fn foo(sutff: Vec<Stuff?) -> Vec<Thing> {
let things = Mutex::new(Vec::new::<Thing>());
stuff.par_iter().for_each(|stuff| {
let thing = stuff.to_thing();
let things = things.lock().unwrap();
things.push(thing);
});
// How do I return the Vec<Thing>?
}
Dereferencing the lock guard does not help.
I am currently doing the following:
let mut things = things.lock().unwrap();
let mut out_things = Vec::new();
out_things.append(&mut things);
return out_things;
Is there a better way to do this?