pub trait UnwrapWithExt<I, O, E, F>{
// Required method
fn unwrap_with(self, _: F) -> UnwrapWith<I, O, E, F> ⓘ;
}
Required Methods§
Sourcefn unwrap_with(self, _: F) -> UnwrapWith<I, O, E, F> ⓘ
fn unwrap_with(self, _: F) -> UnwrapWith<I, O, E, F> ⓘ
Unwraps all results
Errors can be ignored:
use resiter::unwrap::UnwrapWithExt;
use std::str::FromStr;
let unwrapped: Vec<usize> = ["1", "2", "a", "b", "5"]
.iter()
.map(|e| usize::from_str(e))
.unwrap_with(|_| None) // ignore errors
.collect();
assert_eq!(unwrapped, vec![1, 2, 5],);
Or simply converted:
use resiter::unwrap::UnwrapWithExt;
use std::str::FromStr;
let unwrapped: Vec<usize> = ["1", "2", "a", "b", "5"]
.iter()
.map(|e| usize::from_str(e))
.unwrap_with(|_| Some(8)) // convert errors
.collect();
assert_eq!(unwrapped, vec![1, 2, 8, 8, 5],);