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

Trait ResultExt

pub trait ResultExt<T, E> {
    // Required methods
    fn into_error<U>(self) -> Result<T, U> 
       where U: Source,
             E: Error + Send + Sync + 'static;
    fn into_trace<U, R>(self, trace: R) -> Result<T, U> 
       where U: Source,
             R: Debug + Display + Send + Sync + 'static,
             E: Error + Send + Sync + 'static;
    fn into_with_trace<U, R, F>(self, f: F) -> Result<T, U> 
       where U: Source,
             R: Debug + Display + Send + Sync + 'static,
             F: FnOnce() -> R,
             E: Error + Send + Sync + 'static;
    fn trace<R>(self, trace: R) -> Result<T, E> 
       where R: Debug + Display + Send + Sync + 'static,
             E: Trace;
    fn with_trace<R, F>(self, f: F) -> Result<T, E> 
       where R: Debug + Display + Send + Sync + 'static,
             F: FnOnce() -> R,
             E: Trace;
    fn always_ok(self) -> T
       where E: Never;
}
Available on crate feature dep_rkyv only.
Expand description

Helper methods for Results.

Required Methods§

fn into_error<U>(self) -> Result<T, U>
where U: Source, E: Error + Send + Sync + 'static,

Returns a Result with this error type converted to U.

§Example
use rancor::{Failure, ResultExt as _};

let result = "1_000".parse::<i32>().into_error::<Failure>();

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

Returns a Result with this error type converted to U and with an additional trace message added.

§Example
use rancor::{BoxedError, ResultExt as _};

let result = "1_000"
    .parse::<i32>()
    .into_trace::<BoxedError, _>("while parsing 1_000");

fn into_with_trace<U, R, F>(self, f: F) -> Result<T, U>
where U: Source, R: Debug + Display + Send + Sync + 'static, F: FnOnce() -> R, E: Error + Send + Sync + 'static,

Returns a Result with this error type converted to U 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::{BoxedError, ResultExt as _};

let input = "1_000";
let result =
    input
        .parse::<i32>()
        .into_with_trace::<BoxedError, _, _>(|| {
            format!("while parsing {input}")
        });

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

Adds an additional trace message to the error value of this type.

§Example
use rancor::{BoxedError, ResultExt as _};

let result = "1_000"
    .parse::<i32>()
    .into_error::<BoxedError>()
    .trace("while parsing 1_000");

fn with_trace<R, F>(self, f: F) -> Result<T, E>
where R: Debug + Display + Send + Sync + 'static, F: FnOnce() -> R, E: Trace,

Adds an additional trace message to the error value of this type by evaluating the given function f. The function is evaluated only if an error occurred.

§Example
use rancor::{BoxedError, ResultExt as _};

let input = "1_000";
let result = input
    .parse::<i32>()
    .into_error::<BoxedError>()
    .with_trace(|| format!("while parsing {input}"));

fn always_ok(self) -> T
where E: Never,

Safely unwraps a result that is always Ok.

In order to call this method, the error type of this Result must be a Never type.

§Example
use rancor::{Infallible, ResultExt};

let inner = Ok::<i32, Infallible>(10).always_ok();

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, E> ResultExt<T, E> for Result<T, E>