OrFail

Trait OrFail 

Source
pub trait OrFail: Sized {
    type Value;
    type Error;

    // Required methods
    fn or_fail(self) -> Result<Self::Value>;
    fn or_fail_with<F>(self, f: F) -> Result<Self::Value>
       where F: FnOnce(Self::Error) -> String;
}
Expand description

This trait allows for converting a value into Result<_, Failure>.

Required Associated Types§

Source

type Value

Success value type (used for the Ok(_) variant).

Source

type Error

Type of error from which the Failure message is created.

Required Methods§

Source

fn or_fail(self) -> Result<Self::Value>

Returns Err(Failure) if self is a failure value.

If Err(_) is returned, this method should add the current caller location to the backtrace of the resulting Failure.

Source

fn or_fail_with<F>(self, f: F) -> Result<Self::Value>
where F: FnOnce(Self::Error) -> String,

Like OrFail::or_fail(), but allows for customizing the Failure message.

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 OrFail for bool

Source§

type Value = ()

Source§

type Error = ()

Source§

fn or_fail(self) -> Result<Self::Value>

Source§

fn or_fail_with<F>(self, f: F) -> Result<Self::Value>
where F: FnOnce(Self::Error) -> String,

Source§

impl<T> OrFail for Option<T>

Source§

type Value = T

Source§

type Error = ()

Source§

fn or_fail(self) -> Result<Self::Value>

Source§

fn or_fail_with<F>(self, f: F) -> Result<Self::Value>
where F: FnOnce(Self::Error) -> String,

Source§

impl<T, E: Error> OrFail for Result<T, E>

Source§

type Value = T

Source§

type Error = E

Source§

fn or_fail(self) -> Result<Self::Value>

Source§

fn or_fail_with<F>(self, f: F) -> Result<Self::Value>
where F: FnOnce(Self::Error) -> String,

Implementors§

Source§

impl<T> OrFail for orfail::Result<T>