Trait type_rules::rules::Rule
source · [−]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::{Validator, Rule};
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
impl Rule<Option<&'_ str>> for MaxLength
impl Rule<Option<&'_ str>> for MinLength
impl Rule<Option<&'_ str>> for MinMaxLength
impl Rule<Option<String>> for MaxLength
impl Rule<Option<String>> for MinLength
impl Rule<Option<String>> for MinMaxLength
impl Rule<str> for MaxLength
impl Rule<str> for MinLength
impl Rule<str> for MinMaxLength
impl Rule<String> for MaxLength
impl Rule<String> for MinLength
impl Rule<String> for MinMaxLength
impl<'a> Rule<Option<&'_ str>> for RegEx<'a>
Available on crate feature
regex
only.impl<'a> Rule<Option<String>> for RegEx<'a>
Available on crate feature
regex
only.impl<'a> Rule<str> for RegEx<'a>
Available on crate feature
regex
only.impl<'a> Rule<String> for RegEx<'a>
Available on crate feature
regex
only.