Skip to main content

ErrorExt

Trait ErrorExt 

Source
pub trait ErrorExt {
    // Required method
    fn report(&self) -> ErrorReport<'_>;
}
Expand description

Extension trait for std::error::Error.

This trait is implemented for all types that implement Error, providing additional methods for working with errors.

§Example

use std::error::Error;
use scoped_error::ErrorExt;

fn handle_error(e: impl Error + 'static) {
    let report = e.report();
    println!("{}", report);
}

Required Methods§

Source

fn report(&self) -> ErrorReport<'_>

Generate a formatted error report for this error.

The report includes the error message and all causes in the chain, formatted for human readability.

§Example
use scoped_error::{Error, expect_error, ErrorExt};

let result: Result<(), Error> = expect_error("Outer", || {
    Err("Inner")?;
    Ok(())
});

if let Err(e) = result {
    println!("{}", e.report());
}

Implementors§

Source§

impl<T> ErrorExt for T
where T: Error + 'static,