ResultExt

Trait ResultExt 

Source
pub trait ResultExt {
    type Success;
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn or_raise<A, F>(self, err: F) -> Result<Self::Success, Exn<A>>
       where A: Error + Send + Sync + 'static,
             F: FnOnce() -> A;
    fn or_erased(self) -> Result<Self::Success, Exn>;
    fn or_raise_erased<A, F>(self, err: F) -> Result<Self::Success, Exn>
       where A: Error + Send + Sync + 'static,
             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: Error + Send + Sync + 'static

The Err type that would be wrapped in an Exn.

Required Methods§

Source

fn or_raise<A, F>(self, err: F) -> Result<Self::Success, Exn<A>>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Raise a new exception on the Exn inside the Result.

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

Source

fn or_erased(self) -> Result<Self::Success, Exn>

Raise a new exception on the Exn inside the Result, but erase its type.

Apply Exn::erased on the Err variant, refer to it for more information.

Source

fn or_raise_erased<A, F>(self, err: F) -> Result<Self::Success, Exn>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Raise a new exception on the Exn inside the Result, and type-erase the result.

Apply Exn::raise and Exn::erased 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, Exn<E>>
where E: Error + Send + Sync + 'static,

Source§

type Success = T

Source§

type Error = E

Source§

fn or_raise<A, F>(self, err: F) -> Result<Self::Success, Exn<A>>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Source§

fn or_erased(self) -> Result<Self::Success, Exn>

Source§

fn or_raise_erased<A, F>(self, err: F) -> Result<Self::Success, Exn>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Source§

impl<T, E> ResultExt for Result<T, E>
where E: Error + Send + Sync + 'static,

Source§

type Success = T

Source§

type Error = E

Source§

fn or_raise<A, F>(self, err: F) -> Result<Self::Success, Exn<A>>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Source§

fn or_erased(self) -> Result<Self::Success, Exn>

Source§

fn or_raise_erased<A, F>(self, err: F) -> Result<Self::Success, Exn>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Implementors§