rancor

Trait OptionExt

Source
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§

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>();
Source

fn into_trace<E, R>(self, trace: R) -> Result<T, E>
where E: Source, R: Debug + Display + Send + Sync + 'static,

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)");
Source

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,

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.

Implementations on Foreign Types§

Source§

impl<T> OptionExt<T> for Option<T>

Source§

fn into_error<E>(self) -> Result<T, E>
where E: Source,

Source§

fn into_trace<E, R>(self, trace: R) -> Result<T, E>
where E: Source, R: Debug + Display + Send + Sync + 'static,

Source§

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,

Implementors§