[][src]Crate fool

Traits for interoperation of Boolean and sum types.

Fool provides extension traits for bool, Option, and Result types. These traits enable fluent conversions and expressions.

Examples

Using and_if to produce an Option if a predicate succeeds:

use fool::prelude::*;

pub fn get<T>() -> Option<T> {
    // ...
}

if let Some(value) = get::<u32>().and_if(|value| *value > 10) {
    // ...
}

Using some_with to produce an Option based on a Boolean expression:

use fool::prelude::*;
use std::collections::HashSet;

let mut set = HashSet::new();
set.insert(10u32);

let message = set.contains(&10u32).some_with(|| "Contains 10!".to_owned());

Modules

prelude

Traits

BoolExt
OptionExt