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>whereE: ErrorResult<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§
Required Methods§
Sourcefn change_context<E: Error + Sized + Send + Sync + 'static>(
self,
error: E,
) -> Result<Self::Ok, ErrorReport>
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.
Sourcefn error_attach<S: Into<String>>(
self,
key_name: S,
attachment: ErrorSensitivityLabel<ErrorAttachment>,
) -> Result<Self::Ok, ErrorReport>
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.
Sourcefn error_attach_public_string<S: Into<String>>(
self,
key_name: S,
attachment: String,
) -> Result<Self::Ok, ErrorReport>
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.
Sourcefn unwrap_error(self) -> Self::Ok
fn unwrap_error(self) -> Self::Ok
Unwrap the value, panicking with a full ErrorReport on Err/None.
Sourcefn expect_error(self, msg: &str) -> Self::Ok
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.