pub trait OptionExt: Sealed {
type Error: Error;
// Required methods
fn capture<E, K>(error_kind: K, option: Option<E>) -> Self
where E: Context,
K: ErrorKind + Into<<Self::Error as Error>::Kind>,
Self::Error: TrivialError;
fn convert<E, K>(error_kind: K, option: Option<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 Option<T> when T is an Error.
Required Associated Types§
Required Methods§
Sourcefn capture<E, K>(error_kind: K, option: Option<E>) -> Self
fn capture<E, K>(error_kind: K, option: Option<E>) -> Self
Convert an option from some foreign error, capturing the error context.
This is equivalent to the following code:
match option {
Some(error) => Some(
TargetError::new(error_kind.into()).with_context(|| error)
),
None => None,
}Sourcefn convert<E, K>(error_kind: K, option: Option<E>) -> Self
fn convert<E, K>(error_kind: K, option: Option<E>) -> Self
Convert an option from some foreign error.
This is equivalent to the following code:
match option {
Some(error) => Some(TargetError::new(error_kind.into())),
None => None,
}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 Some(value). If the Option is None, this information
is discarded.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".