#[macro_use] extern crate derive_more; extern crate erroneous; use erroneous::Error; use std::error::Error as _; #[derive(Debug, Display, Error)] #[display(fmt = "A")] struct A; #[derive(Debug, Display, Error)] #[display(fmt = "B")] struct B(#[error(source)] A); #[derive(Debug, Display, Error)] #[display(fmt = "C")] struct C(#[error(source)] B); #[derive(Debug, Display, Error)] #[display(fmt = "{}", _0)] struct D(#[error(defer)] C); #[test] fn source() { let e = D(C(B(A))); let e = e.source().unwrap(); assert!(e.is::()); let e = e.source().unwrap(); assert!(e.is::()); assert!(e.source().is_none()); } #[test] fn iter() { let mut e = D(C(B(A))).iter(); assert!(e.next().unwrap().is::()); assert!(e.next().unwrap().is::()); assert!(e.next().unwrap().is::()); assert!(e.next().is_none()); }