devela::_dep::rkyv::bytecheck::rancor

Trait OptionExt

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;
}
Available on crate feature dep_rkyv only.
Expand description

Helper methods for Options.

Required Methods§

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

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

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.

Implementors§

§

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