pub trait Rule<T: ?Sized> {
    fn check(&self, value: &T) -> Result<(), String>;
}
Expand description

Define a rule for a type

By implementing Rule for a type you define how it will be used to constraint a type T

Example

use type_rules::prelude::*;

struct IsEven();

impl Rule<i32> for IsEven {
    fn check(&self, value: &i32) -> Result<(), String> {
        if value % 2 == 0 {
            Ok(())
        } else {
            Err("Value is not even".into())
        }
    }
}

#[derive(Validator)]
struct MyInteger(#[rule(IsEven())] i32);

Required Methods

Implementors