diff --git a/src/context.rs b/src/context.rs index 8d75dad..2f78b95 100644 --- a/src/context.rs +++ b/src/context.rs @@ -201,6 +201,16 @@ impl IntoContext for Location<'static> { } } +impl IntoContext for Arc +where + E: std::error::Error + Send + Sync + 'static, +{ + #[inline] + fn into_context(self) -> Context { + Context::new(Detail::Error(PrivateError(self))) + } +} + impl IntoContext for F where C: IntoContext, diff --git a/src/explain.rs b/src/explain.rs index ee11195..691d47a 100644 --- a/src/explain.rs +++ b/src/explain.rs @@ -1,8 +1,7 @@ use std::panic::Location; use std::sync::Arc; -use crate::{How, IntoContext, Context, Detail}; -use crate::context::PrivateError; +use crate::{How, IntoContext, Detail}; pub trait Explain { type Output; @@ -73,7 +72,7 @@ where #[track_caller] fn context(self, context: impl IntoContext) -> Self::Output { - How::new(Context::new(Detail::Error(PrivateError(self)))) + How::new(self.into_context()) .context(context) } }