Add a `frame` method to Explain
This commit is contained in:
parent
a888990a2a
commit
60b4547267
|
@ -3,20 +3,17 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{How, IntoContext, Detail};
|
use crate::{How, IntoContext, Detail};
|
||||||
|
|
||||||
pub trait Explain {
|
pub trait Explain: Sized {
|
||||||
type Output;
|
type Output;
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn context(self, context: impl IntoContext) -> Self::Output;
|
fn context(self, context: impl IntoContext) -> Self::Output;
|
||||||
}
|
|
||||||
|
|
||||||
impl Explain for How {
|
|
||||||
type Output = Self;
|
|
||||||
|
|
||||||
#[track_caller]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn context(mut self, context: impl IntoContext) -> Self {
|
#[track_caller]
|
||||||
|
#[must_use]
|
||||||
|
fn frame(self, context: impl IntoContext) -> Self::Output {
|
||||||
let mut context = context.into_context();
|
let mut context = context.into_context();
|
||||||
|
|
||||||
context.extra.reserve(if cfg!(feature = "extra-backtrace") {
|
context.extra.reserve(if cfg!(feature = "extra-backtrace") {
|
||||||
|
@ -27,7 +24,18 @@ impl Explain for How {
|
||||||
context.extra.push(Detail::Location(*Location::caller()));
|
context.extra.push(Detail::Location(*Location::caller()));
|
||||||
#[cfg(feature = "extra-backtrace")]
|
#[cfg(feature = "extra-backtrace")]
|
||||||
context.extra.push(Detail::backtrace());
|
context.extra.push(Detail::backtrace());
|
||||||
self.push_context(context);
|
|
||||||
|
self.context(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Explain for How {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
#[track_caller]
|
||||||
|
fn context(mut self, context: impl IntoContext) -> Self {
|
||||||
|
self.push_context(context.into_context());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,20 +78,20 @@ where
|
||||||
{
|
{
|
||||||
type Output = How;
|
type Output = How;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn context(self, context: impl IntoContext) -> Self::Output {
|
fn context(self, context: impl IntoContext) -> Self::Output {
|
||||||
How::new(self.into_context())
|
How::new(self).context(context)
|
||||||
.context(context)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Explain for Arc<dyn std::error::Error + Send + Sync> {
|
impl Explain for Arc<dyn std::error::Error + Send + Sync> {
|
||||||
type Output = How;
|
type Output = How;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn context(self, context: impl IntoContext) -> Self::Output {
|
fn context(self, context: impl IntoContext) -> Self::Output {
|
||||||
How::new(self.into_context())
|
How::new(self).context(context)
|
||||||
.context(context)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ impl How {
|
||||||
location,
|
location,
|
||||||
context: Vec::with_capacity(4),
|
context: Vec::with_capacity(4),
|
||||||
}))
|
}))
|
||||||
.context(context);
|
.frame(context);
|
||||||
#[cfg(all(feature = "backtrace", not(feature = "extra-backtrace")))]
|
#[cfg(all(feature = "backtrace", not(feature = "extra-backtrace")))]
|
||||||
how.top_mut().extra.push(Detail::backtrace());
|
how.top_mut().extra.push(Detail::backtrace());
|
||||||
how
|
how
|
||||||
|
|
Loading…
Reference in New Issue