Add IntoContext and Explain for Arc<dyn Error>

This commit is contained in:
Michael Pfaff 2023-07-01 13:11:42 -04:00
parent 8a055af669
commit 0e0eaa8d2e
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
2 changed files with 17 additions and 0 deletions

View File

@ -218,6 +218,13 @@ where
}
}
impl IntoContext for Arc<dyn std::error::Error + Send + Sync> {
#[inline]
fn into_context(self) -> Context {
Context::new(Detail::Error(PrivateError(self)))
}
}
impl<C, F> IntoContext for F
where
C: IntoContext,

View File

@ -77,6 +77,16 @@ where
}
}
impl Explain for Arc<dyn std::error::Error + Send + Sync> {
type Output = How;
#[track_caller]
fn context(self, context: impl IntoContext) -> Self::Output {
How::new(self.into_context())
.context(context)
}
}
impl<T> Explain for Option<T> {
type Output = Result<T, How>;