Struct tracing_error::TracedError [−][src]
pub struct TracedError<E> { /* fields omitted */ }
This is supported on crate feature
traced-error
only.Expand description
A wrapper type for Error
s that bundles a SpanTrace
with an inner Error
type.
This type is a good match for the error-kind pattern where you have an error type with an inner enum of error variants and you would like to capture a span trace that can be extracted during printing without formatting the span trace as part of your display impl.
An example of implementing an error type for a library using TracedError
might look like this
ⓘ
#[derive(Debug, thiserror::Error)]
enum Kind {
// ...
}
#[derive(Debug)]
pub struct Error {
source: TracedError<Kind>,
backtrace: Backtrace,
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.source.source()
}
fn backtrace(&self) -> Option<&Backtrace> {
Some(&self.backtrace)
}
}
impl fmt::Display for Error {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.source, fmt)
}
}
impl<E> From<E> for Error
where
Kind: From<E>,
{
fn from(source: E) -> Self {
Self {
source: Kind::from(source).into(),
backtrace: Backtrace::capture(),
}
}
}
Trait Implementations
Auto Trait Implementations
impl<E> !RefUnwindSafe for TracedError<E>
impl<E> Send for TracedError<E> where
E: Send,
impl<E> Sync for TracedError<E> where
E: Sync,
impl<E> Unpin for TracedError<E> where
E: Unpin,
impl<E> !UnwindSafe for TracedError<E>
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more