FallbackIf

Trait FallbackIf 

Source
pub trait FallbackIf<R> {
    // Required method
    fn fallback_if<P, F>(self, predicate: P, alternative: F) -> R
       where P: Into<bool>,
             F: FnOnce() -> R;
}
Expand description

Fallback to an alternative, if the previous result outcome was a fail, and a predicate is true.

Required Methods§

Source

fn fallback_if<P, F>(self, predicate: P, alternative: F) -> R
where P: Into<bool>, F: FnOnce() -> R,

Fallback to an alternative when an outcome is considered a fail and the predicate evaluates to true, otherwise keep the current result.

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> FallbackIf<Option<T>> for Option<T>

Source§

fn fallback_if<P, F>(self, predicate: P, alternative: F) -> Option<T>
where P: Into<bool>, F: FnOnce() -> Option<T>,

Source§

impl<T, E> FallbackIf<Result<T, E>> for Result<T, E>

Source§

fn fallback_if<P, F>(self, predicate: P, alternative: F) -> Result<T, E>
where P: Into<bool>, F: FnOnce() -> Result<T, E>,

Fallback to an alternative when a result produces an error and the predicate evaluates to true, otherwise keep the current result.

Implementors§