pub struct ErrorTraceFormatter<'s, 'e1, 'e2> { /* private fields */ }Expand description
Formats an error and all its dependencies.
If you have the colors-feature enabled, then you can also use ErrorTraceColorFormatter to
do the same but with ANSI-colors.
§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, 'e1, 'e2> ErrorTraceFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> ErrorTraceFormatter<'s, 'e1, 'e2>
Sourcepub fn new(
msg: impl Into<Cow<'s, str>>,
err: Option<&'e1 (dyn Error + 'e2)>,
) -> Self
pub fn new( msg: impl Into<Cow<'s, str>>, err: Option<&'e1 (dyn Error + 'e2)>, ) -> 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 toplevel!-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, 'e1, 'e2> Freeze for ErrorTraceFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> !RefUnwindSafe for ErrorTraceFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> !Send for ErrorTraceFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> !Sync for ErrorTraceFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> Unpin for ErrorTraceFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> !UnwindSafe for ErrorTraceFormatter<'s, 'e1, 'e2>
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