Trait AsReport

Source
pub trait AsReport: Sealed {
    // Required method
    fn as_report(&self) -> Report<'_>;

    // Provided methods
    fn to_report_string(&self) -> String { ... }
    fn to_report_string_with_backtrace(&self) -> String { ... }
    fn to_report_string_pretty(&self) -> String { ... }
    fn to_report_string_pretty_with_backtrace(&self) -> String { ... }
}
Expand description

Extension trait for Error that provides a Report which formats the error and its sources in a cleaned-up way.

Required Methods§

Source

fn as_report(&self) -> Report<'_>

Returns a Report that formats the error and its sources in a cleaned-up way.

See the documentation for Report for what the formatting looks like under different options.

§Example
use thiserror_ext::AsReport;

let error = fallible_action().unwrap_err();
println!("{}", error.as_report());

Provided Methods§

Source

fn to_report_string(&self) -> String

Converts the error to a Report and formats it in a compact way.

This is equivalent to format!("{}", self.as_report()).

§Example
outer error: middle error: inner error
Source

fn to_report_string_with_backtrace(&self) -> String

Converts the error to a Report and formats it in a compact way, including backtraces if available.

This is equivalent to format!("{:?}", self.as_report()).

§Example
outer error: middle error: inner error

Backtrace:
  ...
Source

fn to_report_string_pretty(&self) -> String

Converts the error to a Report and formats it in a pretty way.

This is equivalent to format!("{:#}", self.as_report()).

§Example
outer error

Caused by these errors (recent errors listed first):
  1: middle error
  2: inner error
Source

fn to_report_string_pretty_with_backtrace(&self) -> String

Converts the error to a Report and formats it in a pretty way,

including backtraces if available.

§Example
outer error

Caused by these errors (recent errors listed first):
  1: middle error
  2: inner error

Backtrace:
  ...

Implementations on Foreign Types§

Source§

impl AsReport for dyn Error

Source§

fn as_report(&self) -> Report<'_>

Source§

impl AsReport for dyn Error + Send

Source§

fn as_report(&self) -> Report<'_>

Source§

impl AsReport for dyn Error + Send + Sync

Source§

fn as_report(&self) -> Report<'_>

Source§

impl AsReport for dyn Error + Send + Sync + UnwindSafe

Source§

fn as_report(&self) -> Report<'_>

Source§

impl AsReport for dyn Error + Sync

Source§

fn as_report(&self) -> Report<'_>

Implementors§

Source§

impl<T: Error> AsReport for T