Skip to main content

Pick

Trait Pick 

Source
pub trait Pick<O>: Sealed {
    // Required methods
    fn pick(self, when_true: O, when_false: O) -> O;
    fn pick_lazy<P, N>(self, when_true: P, when_false: N) -> O
       where P: FnOnce() -> O,
             N: FnOnce() -> O;
}

Required Methods§

Source

fn pick(self, when_true: O, when_false: O) -> O

Source

fn pick_lazy<P, N>(self, when_true: P, when_false: N) -> O
where P: FnOnce() -> O, N: FnOnce() -> O,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<O> Pick<O> for bool

Source§

fn pick(self: bool, when_true: O, when_false: O) -> O

Example:

use conditional_assignment::Pick;
let condition = 0 < 1;
let outcome = if condition {
   "true"
} else {
   "false"
};
Source§

fn pick_lazy<P, N>(self: bool, when_true: P, when_false: N) -> O
where P: FnOnce() -> O, N: FnOnce() -> O,

Example:

use conditional_assignment::Pick;
let condition = 0 < 1;
let outcome = condition.pick_lazy(
    || {
        assert!(condition);
        "true"
    },
    || {
        assert!(!condition);
        "false"
    },
);

Implementors§