I know it's possible to turn a vector with type Vec<Result<T, ()>> into a Result<Vec, ()>. But I haven't found a way to do it the other way round, that is turn a Vec<Result<(), T>> into a Result<(), Vec>.
In my case, I'm writing a collision function for a physics engine. You supply a function with a slice of objects that it might collide with, it runs a simulation, and returns either a blank Ok(()), or an error with a boxed slice of items it collided with. I can do this:
let results1: Vec<Result<usize, ()>> = vec![ Ok(0), Ok(1), Ok(2), Err(()), ]; let result1 = results1.clone().into_iter() .collect::<Result<Vec<_>, ()>>();
But this won't compile:
let results2: Vec<Result<(), usize>> = vec![ Ok(()), Ok(()), Ok(()), Err(3), Err(3), ]; let result2 = results2.clone().into_iter() .collect::<Result<(), Vec<_>>>();
Is it that conversion just not implemented, or am I missing something?