pub trait OptionExt<T> {
// Required methods
fn into_error<E>(self) -> Result<T, E>
where E: Source;
fn into_trace<E, R>(self, trace: R) -> Result<T, E>
where E: Source,
R: Debug + Display + Send + Sync + 'static;
fn into_with_trace<E, R, F>(self, f: F) -> Result<T, E>
where E: Source,
R: Debug + Display + Send + Sync + 'static,
F: FnOnce() -> R;
}Expand description
Helper methods for Options.
Required Methods§
Sourcefn into_error<E>(self) -> Result<T, E>where
E: Source,
fn into_error<E>(self) -> Result<T, E>where
E: Source,
Returns a Result with an error indicating that Some was expected but
None was found.
§Example
use rancor::{Failure, OptionExt};
let result = Some(10).into_error::<Failure>();Sourcefn into_trace<E, R>(self, trace: R) -> Result<T, E>
fn into_trace<E, R>(self, trace: R) -> Result<T, E>
Returns a Result with an error indicating that Some was expected but
None was found, and with an additional trace message added.
§Example
use rancor::{Failure, OptionExt};
#[rustfmt::skip]
let result = Some(10).
into_trace::<Failure, _>("while converting Some(10)");Sourcefn into_with_trace<E, R, F>(self, f: F) -> Result<T, E>
fn into_with_trace<E, R, F>(self, f: F) -> Result<T, E>
Returns a Result with an error indicating that Some was expected but
None was found, and with an additional trace message added by
evaluating the given function f. The function is evaluated only if an
error occurred.
§Example
use rancor::{Failure, OptionExt};
let input = Some(10);
let result = input.into_with_trace::<Failure, _, _>(|| {
format!("while converting {input:?}")
});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.