StashErrorsIter

Trait StashErrorsIter 

Source
pub trait StashErrorsIter<T, W, E, S>
where E: Display + Debug + Send + 'static, W: Send + 'static, S: ErrorStash<E, W>,
{ // Required method fn stash_errors(self, stash: &mut S) -> impl Iterator<Item = T>; }
Expand description

Adds a stash_errors method to iterators of Result<T, E>, allowing errors to be collected into an ErrorStash while producing an iterator of unwrapped values.

Required Methods§

Source

fn stash_errors(self, stash: &mut S) -> impl Iterator<Item = T>

Converts an iterator of Result<T, E> into an iterator of T, collecting all errors into the provided ErrorStash.

§Arguments
  • stash - A mutable reference to an ErrorStash where errors will be collected
§Returns

An iterator that yields only the unwrapped Ok values from the original iterator. All Err values are collected in the provided ErrorStash.

Note: The returned iterator borrows stash mutably for its entire lifetime.

§Example
use errorstash::{ErrorStash, StashErrorsIter, BoxedStash};
use anyhow::{Error, anyhow};

let mut stash = BoxedStash::new();
let results = vec![Ok(1), Err(anyhow!("error")), Ok(2)];
let values: Vec<i32> = results.into_iter().stash_errors(&mut stash).collect();

assert_eq!(values, vec![1, 2]);
assert_eq!(stash.len(), 1);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<I, T, W, E, FE, S> StashErrorsIter<T, W, E, S> for I
where I: Iterator<Item = Result<T, FE>>, FE: Into<E>, E: Display + Debug + Send + 'static, W: Error + Send + 'static, S: ErrorStash<E, W>,

Implements StashErrorsIter for iterators over Result<T, E>, allowing errors to be stashed and values to be collected.