ReportAs

Trait ReportAs 

Source
pub trait ReportAs<T> {
    // Required method
    fn report_as<C: ThinContext>(self) -> Result<T, Report<C>>;
}
Expand description

Trait for converting Result<T, E> into Result<T, Report<C>> with automatic error wrapping.

This trait extends the functionality of error_stack::IntoReport by allowing implicit conversion from any error type to a specific context type with enhanced error reporting that includes source chain information.

Required Methods§

Source

fn report_as<C: ThinContext>(self) -> Result<T, Report<C>>

Convert this result into a report with the specified context type.

This method automatically converts any Result<T, E> where E implements Context + Error into a Result<T, Report<C>> where C is your desired context type.

§Example
use bigerror::{ReportAs, ThinContext, Report};

#[derive(ThinContext)]
struct MyError;

fn parse_number(s: &str) -> Result<i32, Report<MyError>> {
    s.parse().report_as() // Converts ParseIntError automatically
}

// Error includes original ParseIntError details + type information
let result = parse_number("not_a_number");
assert!(result.is_err());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T, E: Context + Error> ReportAs<T> for Result<T, E>

Implementors§