Crate error_iter

source ·
Expand description

Iterators over std::error::Error sources on stable Rust.

use error_iter::ErrorIter as _;
use std::io::{Error as IoError, ErrorKind};
use thiserror::Error;

#[derive(Debug, Error)]
enum Error {
    #[error("I/O Error")]
    Io(#[from] IoError),

    #[error("Unknown error")]
    Unknown,
}

fn do_something() {
    let error = Error::from(IoError::new(ErrorKind::Other, "oh no!"));

    eprintln!("Error: {}", error);
    for source in error.sources().skip(1) {
        eprintln!("  Caused by: {}", source);
    }
}

Structs

Traits

  • Implement this trait on your error types for free iterators over their sources!