pub trait ResultExt<T, E> {
// Required method
fn ctx(self, build: impl FnOnce() -> Context) -> Result<T, Error>
where E: CoreError + Send + Sync + 'static;
}Expand description
Extension trait for enriching Result errors with Context.
The ctx method converts the error side of a Result
into Error while attaching metadata, category and edit policy captured
by Context.
§Examples
use std::io::{Error as IoError, ErrorKind};
use masterror::{AppErrorKind, Context, ResultExt, field};
fn validate() -> Result<(), IoError> {
Err(IoError::from(ErrorKind::Other))
}
let err = validate()
.ctx(|| Context::new(AppErrorKind::Validation).with(field::str("phase", "validate")))
.unwrap_err();
assert_eq!(err.kind, AppErrorKind::Validation);
assert!(err.metadata().get("phase").is_some());Required Methods§
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.