Implement IntoContext for Arc<Error>

This commit is contained in:
Michael Pfaff 2023-07-01 12:45:30 -04:00
parent db067003d8
commit c945f1241e
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
2 changed files with 12 additions and 3 deletions

View File

@ -201,6 +201,16 @@ impl IntoContext for Location<'static> {
}
}
impl<E> IntoContext for Arc<E>
where
E: std::error::Error + Send + Sync + 'static,
{
#[inline]
fn into_context(self) -> Context {
Context::new(Detail::Error(PrivateError(self)))
}
}
impl<C, F> IntoContext for F
where
C: IntoContext,

View File

@ -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)
}
}