Skip to main content

ResultExt

Trait ResultExt 

Source
pub trait ResultExt {
    type Ok;

    // Required methods
    fn change_context<E: Error + Sized + Send + Sync + 'static>(
        self,
        error: E,
    ) -> Result<Self::Ok, ErrorReport>;
    fn error_attach<S: Into<String>>(
        self,
        key_name: S,
        attachment: ErrorSensitivityLabel<ErrorAttachment>,
    ) -> Result<Self::Ok, ErrorReport>;
    fn error_attach_public_string<S: Into<String>>(
        self,
        key_name: S,
        attachment: String,
    ) -> Result<Self::Ok, ErrorReport>;
    fn unwrap_error(self) -> Self::Ok;
    fn expect_error(self, msg: &str) -> Self::Ok;
}
Expand description

Extension trait for Result and Option that integrates with ErrorReport.

Provides methods to wrap errors with context, attach diagnostic data, and unwrap with rich panic messages.

Implemented for:

  • Result<T, E> where E: Error
  • Result<T, ErrorReport>
  • Option<T>

§Example

use charon_error::prelude::*;

fn read_config() -> ResultER<String> {
    std::fs::read_to_string("config.toml")
        .change_context(StringError::new("failed to read config"))
}

Required Associated Types§

Source

type Ok

Type of the Ok value in the Result.

Required Methods§

Source

fn change_context<E: Error + Sized + Send + Sync + 'static>( self, error: E, ) -> Result<Self::Ok, ErrorReport>

Wrap the error in a new ErrorReport (or push onto an existing one) with the given higher-level error as context.

Source

fn error_attach<S: Into<String>>( self, key_name: S, attachment: ErrorSensitivityLabel<ErrorAttachment>, ) -> Result<Self::Ok, ErrorReport>

Attach labeled data to the error report on the Err path.

Source

fn error_attach_public_string<S: Into<String>>( self, key_name: S, attachment: String, ) -> Result<Self::Ok, ErrorReport>

Shorthand to attach a public string to the error report.

Source

fn unwrap_error(self) -> Self::Ok

Unwrap the value, panicking with a full ErrorReport on Err/None.

Source

fn expect_error(self, msg: &str) -> Self::Ok

Unwrap the value with a custom message, panicking with a full ErrorReport.

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> ResultExt for Option<T>

Source§

type Ok = T

Source§

fn change_context<R: Error + Sized + Send + Sync + 'static>( self, error: R, ) -> Result<T, ErrorReport>

Source§

fn error_attach<S: Into<String>>( self, key_name: S, attachment: ErrorSensitivityLabel<ErrorAttachment>, ) -> Result<T, ErrorReport>

Source§

fn error_attach_public_string<S: Into<String>>( self, key_name: S, attachment: String, ) -> Result<T, ErrorReport>

Source§

fn unwrap_error(self) -> T

Source§

fn expect_error(self, msg: &str) -> T

Source§

impl<T> ResultExt for Result<T, ErrorReport>

Source§

type Ok = T

Source§

fn change_context<R: Error + Sized + Send + Sync + 'static>( self, error: R, ) -> Result<T, ErrorReport>

Source§

fn error_attach<S: Into<String>>( self, key_name: S, attachment: ErrorSensitivityLabel<ErrorAttachment>, ) -> Result<T, ErrorReport>

Source§

fn error_attach_public_string<S: Into<String>>( self, key_name: S, attachment: String, ) -> Result<T, ErrorReport>

Source§

fn unwrap_error(self) -> T

Source§

fn expect_error(self, msg: &str) -> T

Source§

impl<T, E> ResultExt for Result<T, E>
where E: Error + Sized + Send + Sync + 'static,

Source§

type Ok = T

Source§

fn change_context<R: Error + Sized + Send + Sync + 'static>( self, error: R, ) -> Result<T, ErrorReport>

Source§

fn error_attach<S: Into<String>>( self, key_name: S, attachment: ErrorSensitivityLabel<ErrorAttachment>, ) -> Result<T, ErrorReport>

Source§

fn error_attach_public_string<S: Into<String>>( self, key_name: S, attachment: String, ) -> Result<T, ErrorReport>

Source§

fn unwrap_error(self) -> T

Source§

fn expect_error(self, msg: &str) -> T

Implementors§