Struct tracing_error::TracedError
source · pub struct TracedError<E> { /* private fields */ }
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§
source§impl<E> Debug for TracedError<E>where
E: Error,
impl<E> Debug for TracedError<E>where
E: Error,
source§impl<E> Display for TracedError<E>where
E: Error,
impl<E> Display for TracedError<E>where
E: Error,
source§impl<E> Error for TracedError<E>where
E: Error + 'static,
impl<E> Error for TracedError<E>where
E: Error + 'static,
source§fn source<'a>(&'a self) -> Option<&'a (dyn Error + 'static)>
fn source<'a>(&'a self) -> Option<&'a (dyn Error + 'static)>
The lower-level source of this error, if any. Read more
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl<E> Freeze for TracedError<E>where
E: Freeze,
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<E> InstrumentError for Ewhere
TracedError<E>: From<E>,
impl<E> InstrumentError for Ewhere
TracedError<E>: From<E>,
§type Instrumented = TracedError<E>
type Instrumented = TracedError<E>
The type of the wrapped error after instrumentation
source§fn in_current_span(self) -> <E as InstrumentError>::Instrumented
fn in_current_span(self) -> <E as InstrumentError>::Instrumented
Instrument an Error by bundling it with a SpanTrace Read more