Using ? with a Vec

  1. suppose we have:
x: Result<T, E>

then we can do:

x?
  1. Now, suppose instead we have:
v: Vec<Result<T, E>>;

is there a way to apply ? to the entire Vec? either it returns the first E, or it returns a Vec ?

You can use this implementation of FromIterator: v.into_iter().collect()?. But it would be more efficient to do it before you create the initial Vec.

2 Likes