Trait type_rules::Validator
source · [−]pub trait Validator {
fn check_validity(&self) -> Result<(), String>;
}
Expand description
Check the validity of a type
By implementing Validator
for a type, you define the
rules to check is validity
Can be derived with the derive
feature
Example
Basic usage:
ⓘ
use type_rules::prelude::*;
#[derive(Validator)]
struct NotEmptyString(#[rule(MinLength(1))] String);
let valid = NotEmptyString(String::from("Not empty"));
let not_valid = NotEmptyString(String::from(""));
valid.check_validity().unwrap(); // OK
not_valid.check_validity().unwrap(); // Value is too short