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>

source

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’s Error::source()-implementation.
§Returns

A new ErrorTraceFormatter ready to rock-n-roll.

Trait Implementations§

source§

impl<'s, 'e> Display for ErrorTraceFormatter<'s, 'e>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> FResult

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.