pub trait ResultExt: Sealed {
type Error: Error;
type Result: Sized;
// Required methods
fn capture<E, K>(error_kind: K, result: Result<Self::Result, E>) -> Self
where E: Context,
K: ErrorKind + Into<<Self::Error as Error>::Kind>,
Self::Error: TrivialError;
fn convert<E, K>(error_kind: K, result: Result<Self::Result, E>) -> Self
where E: Context,
K: ErrorKind + Into<<Self::Error as Error>::Kind>,
Self::Error: TrivialError;
fn with_context<C, F>(self, context: F) -> Self
where C: Context,
F: FnOnce() -> C;
}Expand description
Extension functions for Result<T, E> when E is an Error.
Required Associated Types§
Required Methods§
Sourcefn capture<E, K>(error_kind: K, result: Result<Self::Result, E>) -> Self
fn capture<E, K>(error_kind: K, result: Result<Self::Result, E>) -> Self
Convert a result from some foreign error, capturing the error context.
This is equivalent to the following code:
match result {
Ok(value) => Ok(value),
Err(error) => Err(
TargetError::new(error_kind.into()).with_context(|| error)
),
}Sourcefn convert<E, K>(error_kind: K, result: Result<Self::Result, E>) -> Self
fn convert<E, K>(error_kind: K, result: Result<Self::Result, E>) -> Self
Convert a result from some foreign error.
This is equivalent to the following code:
match result {
Ok(value) => Ok(value),
Err(_) => Err(TargetError::new(error_kind.into())),
}Sourcefn with_context<C, F>(self, context: F) -> Self
fn with_context<C, F>(self, context: F) -> Self
Provide human-readable information about why an error occurred.
This is a wrapper which redirects to ErrorContext::with_context for
the wrapped Err(error). If the Result is Ok(_), this information
is discarded.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".