How do I avoid unwrap when converting a vector of Options or Results to only the successful values?

Viewed 10426

I have a Vec<Result<T, E>> and I want to ignore all Err values, converting it into a Vec<T>. I can do this:

vec.into_iter().filter(|e| e.is_ok()).map(|e| e.unwrap()).collect()

This is safe, but I want to avoid using unwrap. Is there a better way to write this?

1 Answers
Related