How to convert a Vec<Result<T, E>> to Result<Vec<T>, E>?

I found a solution on StackOverflow: SO

How can this behaviour be better understood?

It works because Result<B, E> itself implements FromIterator if B is a collection of which the element type is itself a Result. It is this impl that removes the "inner" layer of results. There is no magic, and Result isn't special; it's just a clever use of generics.

1 Like

Here's the docs.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.