pub struct ErrorTraceColorFormatter<'s, 'e1, 'e2> { /* private fields */ }Available on crate feature
colors only.Expand description
Formats an error and all its dependencies using neat ANSI-colors if the formatter to which we’re writing supports it.
Whether colors are enabled or not can be checked by console’s
colors_enabled_stderr() function, and controlled by
set_colors_enabled_stderr().
See ErrorTraceFormatter to do the same but without ANSI colors at all.
§Example
use error_trace::{ErrorTraceColorFormatter, ErrorTrace as _};
#[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: ErrorTraceColorFormatter = err.trace_colored();
// Colours aren't visible here, because we're writing to a string; but try writing to stdout/stderr!
assert_eq!(format!("{fmt}"), "Hello, world!");Implementations§
Source§impl<'s, 'e1, 'e2> ErrorTraceColorFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> ErrorTraceColorFormatter<'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 ErrorTraceColourFormatter ready to rock-n-roll.
Trait Implementations§
Auto Trait Implementations§
impl<'s, 'e1, 'e2> Freeze for ErrorTraceColorFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> !RefUnwindSafe for ErrorTraceColorFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> !Send for ErrorTraceColorFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> !Sync for ErrorTraceColorFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> Unpin for ErrorTraceColorFormatter<'s, 'e1, 'e2>
impl<'s, 'e1, 'e2> !UnwindSafe for ErrorTraceColorFormatter<'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