ResultExt

Trait ResultExt 

Source
pub trait ResultExt {
    type Success;
    type Error: ErrorBound;

    // Required methods
    fn or_attach<A, F>(self, context: F) -> Result<Self::Success, Self::Error>
       where A: ContextBound,
             F: FnOnce() -> A;
    fn or_raise<A, F>(self, err: F) -> Result<Self::Success, A>
       where A: ErrorBound,
             F: FnOnce() -> A;
}
Expand description

An extension trait for Result to provide context information on Exns.

Required Associated Types§

Source

type Success

The Ok type.

Source

type Error: ErrorBound

The Err type that would be wrapped in an Exn.

Required Methods§

Source

fn or_attach<A, F>(self, context: F) -> Result<Self::Success, Self::Error>
where A: ContextBound, F: FnOnce() -> A,

Attach a new context to the Exn inside the Result.

Applies Exn::attach on the Err variant, refer to it for more information.

Source

fn or_raise<A, F>(self, err: F) -> Result<Self::Success, A>
where A: ErrorBound, F: FnOnce() -> A,

Raise a new exception on the Exn inside the Result.

Applies Exn::raise on the Err variant, refer to it for more information.

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

Source§

type Success = T

Source§

type Error = <E as IntoExn>::Error

Source§

fn or_attach<A, F>(self, context: F) -> Result<Self::Success, Self::Error>
where A: ContextBound, F: FnOnce() -> A,

Source§

fn or_raise<A, F>(self, err: F) -> Result<Self::Success, A>
where A: ErrorBound, F: FnOnce() -> A,

Implementors§