Skip to content

Commit

Permalink
Provide a default implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
parasyte committed Feb 18, 2023
1 parent 4f139cd commit dbdfcdb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ This crate does not attempt to be 100% compatible with the stabilization effort,
## Show me

`cargo run --example simple`

## Why not a derive macro?

PRs welcome! :)
4 changes: 1 addition & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use error_iter::ErrorIter;
use error_iter::ErrorIter as _;
use std::io::{Error as IoError, ErrorKind};
use thiserror::Error;

Expand All @@ -11,8 +11,6 @@ enum Error {
_Unknown,
}

impl ErrorIter for Error {}

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

Expand Down
12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Iterators over `std::error::Error` sources on stable Rust.
//!
//! ```
//! use error_iter::ErrorIter;
//! use error_iter::ErrorIter as _;
//! use std::io::{Error as IoError, ErrorKind};
//! use thiserror::Error;
//!
Expand All @@ -14,8 +14,6 @@
//! Unknown,
//! }
//!
//! impl ErrorIter for Error {}
//!
//! fn do_something() {
//! let error = Error::from(IoError::new(ErrorKind::Other, "oh no!"));
//!
Expand Down Expand Up @@ -54,7 +52,7 @@ pub trait ErrorIter: std::error::Error + Sized + 'static {
/// Create an iterator over the error and its recursive sources.
///
/// ```
/// use error_iter::ErrorIter;
/// use error_iter::ErrorIter as _;
/// use thiserror::Error;
///
/// #[derive(Debug, Error)]
Expand All @@ -66,8 +64,6 @@ pub trait ErrorIter: std::error::Error + Sized + 'static {
/// Leaf,
/// }
///
/// impl ErrorIter for Error {}
///
/// let error = Error::Nested(Box::new(Error::Leaf));
///
/// let mut iter = error.sources();
Expand All @@ -82,6 +78,8 @@ pub trait ErrorIter: std::error::Error + Sized + 'static {
}
}

impl<T> ErrorIter for T where T: std::error::Error + Sized + 'static {}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -96,8 +94,6 @@ mod tests {
Leaf,
}

impl ErrorIter for Error {}

#[test]
fn iter_sources_ok() {
let error = Error::Nested(Box::new(Error::Nested(Box::new(Error::Leaf))));
Expand Down

0 comments on commit dbdfcdb

Please sign in to comment.