Struct error_trace::ErrorTraceFormatter
source · pub struct ErrorTraceFormatter<'s, 'e> { /* private fields */ }
Expand description
Formats an error and all its dependencies.
If you have the colours
-feature enabled, then you can also use [ErrorTraceColourFormatter
] to do the same but with colours.
§Example
use error_trace::{ErrorTrace as _, ErrorTraceFormatter};
#[derive(Debug)]
struct ExampleError {
msg: String,
}
impl Display for ExampleError {
fn fmt(&self, f: &mut Formatter<'_>) -> FResult { write!(f, "{}", self.msg) }
}
impl Error for ExampleError {}
let err = ExampleError { msg: "Hello, world!".into() };
let fmt: ErrorTraceFormatter = err.trace();
assert_eq!(format!("{fmt}"), "Hello, world!");
Implementations§
source§impl<'s, 'e> ErrorTraceFormatter<'s, 'e>
impl<'s, 'e> ErrorTraceFormatter<'s, 'e>
sourcepub fn new(
msg: impl Into<Cow<'s, str>>,
err: Option<&'e (dyn Error + 'static)>,
) -> Self
pub fn new( msg: impl Into<Cow<'s, str>>, err: Option<&'e (dyn Error + 'static)>, ) -> Self
Builds a formatter for a given “anonymous error”.
This is useful for creating one-time error traces where you don’t want to create the root type.
For even more convenience, see the trace!
-macro.
§Arguments
msg
: A message that is printed as “current error”.err
: An optional error that, if any, will cause this formatter to start printing a trace based on the error’sError::source()
-implementation.
§Returns
A new ErrorTraceFormatter ready to rock-n-roll.
Trait Implementations§
Auto Trait Implementations§
impl<'s, 'e> Freeze for ErrorTraceFormatter<'s, 'e>
impl<'s, 'e> !RefUnwindSafe for ErrorTraceFormatter<'s, 'e>
impl<'s, 'e> !Send for ErrorTraceFormatter<'s, 'e>
impl<'s, 'e> !Sync for ErrorTraceFormatter<'s, 'e>
impl<'s, 'e> Unpin for ErrorTraceFormatter<'s, 'e>
impl<'s, 'e> !UnwindSafe for ErrorTraceFormatter<'s, '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