pub fn fail_all_vec<T, E1, E2, F>(
results: Vec<Result<T, E1>>,
f: F,
) -> Result<Vec<T>, Vec<E2>>
Expand description
If at least one Result
is an error, turn all of them into errors. Else, unwrap the Result
s.
See fail_all for a more generic/low-level version that works with other
input containers and doesn’t collect()
.
§Examples
let err = fail_all_vec(
vec![Ok(A), Err(ErrA), Ok(A)],
|res| res.err().map(HighLevelErr::from).unwrap_or(HighLevelErr::B(ErrB))
);
// Same length as the original, each element turned into an error.
assert_eq!(err, Err(vec![ErrB.into(), ErrA.into(), ErrB.into()]));