contrafact 0.2.0-rc.1

A trait for highly composable constraints ("facts") which can be used both to verify data and to generate arbitrary data within those constraints
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use super::*;

/// A constraint which is always met
pub fn always<'a, T: Target<'a>>() -> Lambda<'a, (), T> {
    lambda_unit("always", |_, t| Ok(t))
}

/// A constraint which is never met
pub fn never<'a, T: Target<'a>>(context: impl ToString) -> Lambda<'a, (), T> {
    let context = context.to_string();
    lambda_unit("never", move |g, t: T| {
        g.fail(context.clone())?;
        Ok(t)
    })
}