diff --git a/src/kind.rs b/src/kind.rs index 9a8a911..be9d9f4 100644 --- a/src/kind.rs +++ b/src/kind.rs @@ -45,7 +45,6 @@ // (&error).anyhow_kind().new(error) use crate::Error; -use std::error::Error as StdError; use std::fmt::{Debug, Display}; #[cfg(backtrace)] @@ -80,13 +79,13 @@ pub trait TraitKind: Sized { } } -impl TraitKind for T where T: StdError + Send + Sync + 'static {} +impl TraitKind for E where E: Into {} impl Trait { pub fn new(self, error: E) -> Error where - E: StdError + Send + Sync + 'static, + E: Into, { - Error::from_std(error, backtrace!()) + error.into() } } diff --git a/tests/test_source.rs b/tests/test_source.rs index 04e9a9a..018267d 100644 --- a/tests/test_source.rs +++ b/tests/test_source.rs @@ -53,3 +53,10 @@ fn test_io_source() { let error = anyhow!(TestError::Io(io)); assert_eq!("oh no!", error.source().unwrap().to_string()); } + +#[test] +fn test_anyhow_from_anyhow() { + let error = anyhow!("oh no!").context("context"); + let error = anyhow!(error); + assert_eq!("oh no!", error.source().unwrap().to_string()); +}