#options #utility #no-std

no-std imply_option

Provides a single trait which allows the construction of an Option based on a bool value

3 releases

Uses old Rust 2015

0.1.2 Jun 14, 2018
0.1.1 Jun 14, 2018
0.1.0 Jun 14, 2018

#171 in #options

0BSD license

3KB

An implementation of this RFC.

Provides a single trait which allows the construction of an Option based on a bool value.

extern crate imply_option;

use imply_option::*;

fn main() {
    let pass = true;

    assert_eq!(pass.then(1), Some(1));
    assert_eq!(pass.then_do(|| 1), Some(1));

    let fail = false;

    assert_eq!(fail.then(1), None);
}

lib.rs:

An implementation of this RFC.

Provides a single trait which allows the construction of an Option based on a bool value.

extern crate imply_option;

use imply_option::*;

fn main() {
    let pass = true;

    assert_eq!(pass.then(1), Some(1));
    assert_eq!(pass.then_do(|| 1), Some(1));

    let fail = false;

    assert_eq!(fail.then(1), None);
}

No runtime deps