From c945f1241ed0f4ff5970b18cd518dd7601821411 Mon Sep 17 00:00:00 2001 From: Michael Pfaff Date: Sat, 1 Jul 2023 12:45:30 -0400 Subject: [PATCH] Implement IntoContext for Arc --- src/context.rs | 10 ++++++++++ src/explain.rs | 5 ++--- 2 files changed, 12 insertions(+), 3 deletions(-) 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) } }