Update: As of 1.33 a functionality like this is available in stdlib (at least for simple type). For iterators you can use iterator.map(Result::transpose)
or iterator.map(Option::transpose)
(thread).
Turn Option<Result<O, E>>
into <Result<Option<O>, E>>
and the other way around.
Also for Iterator
s and potentially other types.
Feel free to submit PR for other types where this operation makes sense.