diff --git a/Cargo.toml b/Cargo.toml index b75acb5..85cb2c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "erdp" description = "Crate for display an error and its nested errors" -version = "0.1.0" +version = "0.1.1" license = "MIT" repository = "https://github.com/ultimaweapon/erdp" edition = "2021" diff --git a/src/lib.rs b/src/lib.rs index d153ac2..b690e29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,12 @@ impl ErrorDisplay for T { } } +impl ErrorDisplay for dyn Error { + fn display(&self) -> Display { + Display(self) + } +} + /// Implementation of [`std::fmt::Display`] for display an error and its nested errors. pub struct Display<'a>(&'a dyn Error); @@ -56,6 +62,13 @@ mod tests { assert_eq!(e.display().to_string(), "nested error -> entity not found"); } + #[test] + fn trait_object() { + let e: Box = Box::new(TestError::Single); + + assert_eq!(e.display().to_string(), "an error without nested errors"); + } + #[derive(Debug, Error)] enum TestError { #[error("an error without nested errors")]