pub trait ResultExt<T, E> {
// Required methods
fn context<C>(self, context: C) -> Result<T, C::Destination>
where C: Contextual<E>;
fn with_context<F, C>(self, context: F) -> Result<T, C::Destination>
where F: FnOnce(&E) -> C,
C: Contextual<E>;
fn boxed(self) -> Result<T, Box<dyn Error + Send + Sync + 'static>>
where E: Error + Send + Sync + 'static;
fn boxed_local(self) -> Result<T, Box<dyn Error + 'static>>
where E: Error + 'static;
}Expand description
Extension trait on Result for ergonomic error context wrapping.
Import via use oopsie::prelude::* or use oopsie::ResultExt.
§Example
use oopsie::{Oopsie, ResultExt as _};
#[derive(Debug, Oopsie)]
#[oopsie(module(false))]
enum IoError {
#[oopsie("IO failed: {source}")]
Failed { source: std::io::Error },
}
let result: Result<(), std::io::Error> = Err(std::io::Error::other("disk full"));
let err = result.context(Failed).unwrap_err();
assert_eq!(err.to_string(), "IO failed: disk full");Required Methods§
Sourcefn context<C>(self, context: C) -> Result<T, C::Destination>where
C: Contextual<E>,
fn context<C>(self, context: C) -> Result<T, C::Destination>where
C: Contextual<E>,
Wrap the error with an eagerly-evaluated context selector.
Sourcefn with_context<F, C>(self, context: F) -> Result<T, C::Destination>
fn with_context<F, C>(self, context: F) -> Result<T, C::Destination>
Wrap the error with a lazily-evaluated context selector.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".