resiter::unwrap

Trait UnwrapWithExt

Source
pub trait UnwrapWithExt<I, O, E, F>
where I: Iterator<Item = Result<O, E>>, F: FnMut(E) -> Option<O>,
{ // Required method fn unwrap_with(self, _: F) -> UnwrapWith<I, O, E, F> ; }

Required Methods§

Source

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],);

Implementors§

Source§

impl<I, O, E, F> UnwrapWithExt<I, O, E, F> for I
where I: Iterator<Item = Result<O, E>>, F: FnMut(E) -> Option<O>,