Struct thiserror_ext::Report

source ·
pub struct Report<'a>(pub &'a dyn Error);
Expand description

A wrapper around an error that provides a cleaned up error trace for display and debug formatting.

Constructed using AsReport::as_report.

§Formatting

The report can be formatted using fmt::Display or fmt::Debug, which differs based on the alternate flag (#).

  • Without the alternate flag, the error is formatted in a compact way:

    Outer error text: Middle error text: Inner error text
    
  • With the alternate flag, the error is formatted in a multi-line format, which is more readable:

    Outer error text
    
    Caused by these errors (recent errors listed first):
      1. Middle error text
      2. Inner error text
    
  • Additionally, fmt::Debug provide backtraces if available.

§Error source cleaning

It’s common for errors with a source to have a Display implementation that includes their source text as well:

Outer error text: Middle error text: Inner error text

This works for smaller errors without much detail, but can be annoying when trying to format the error in a more structured way, such as line-by-line:

1. Outer error text: Middle error text: Inner error text
2. Middle error text: Inner error text
3. Inner error text

This iterator compares each pair of errors in the source chain, removing the source error’s text from the containing error’s text:

1. Outer error text
2. Middle error text
3. Inner error text

Tuple Fields§

§0: &'a dyn Error

Trait Implementations§

source§

impl<'a> Debug for Report<'a>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a> Display for Report<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Report<'a>

§

impl<'a> !RefUnwindSafe for Report<'a>

§

impl<'a> !Send for Report<'a>

§

impl<'a> !Sync for Report<'a>

§

impl<'a> Unpin for Report<'a>

§

impl<'a> !UnwindSafe for Report<'a>

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>,

§

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>,

§

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.