pub trait ResultError<T, D>where
D: Domain,{
// Required methods
fn try_map_on_source<F, S, E>(self, op: F) -> Result<T, Error<D>>
where F: FnOnce(S) -> E,
S: StdError + 'static,
E: Into<Error<D>>;
fn with_context(self, context: impl Display) -> Result<T, Error<D>>;
}
Expand description
To use this trait on Result import the prelude use explicit_error::prelude::*
Required Methods§
Sourcefn try_map_on_source<F, S, E>(self, op: F) -> Result<T, Error<D>>
fn try_map_on_source<F, S, E>(self, op: F) -> Result<T, Error<D>>
Pattern match on the Error source from either the Error::Fault or Error::Domain variant if its type is the closure’s parameter type.
§Examples
let err: Result<()> = Err(MyError::Foo)?;
// Do the map if the source's type of the Error is MyError
err.try_map_on_source(|e| {
match e {
MyError::Foo => HttpError::new(
StatusCode::FORBIDDEN,
ProblemDetails::new()
.with_type(Uri::from_static("/errors/forbidden"))
),
MyError::Bar => HttpError::new(
StatusCode::UNAUTHORIZED,
ProblemDetails::new()
.with_type(Uri::from_static("/errors/unauthorized"))
),
}
})?;
Sourcefn with_context(self, context: impl Display) -> Result<T, Error<D>>
fn with_context(self, context: impl Display) -> Result<T, Error<D>>
Add a context to any variant of an Error wrapped in a Result::Err
§Examples
use explicit_error::{prelude::*, Fault};
Err::<(), _>(Fault::new()).with_context("Foo bar");
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.