pub trait Validator<T> {
// Required methods
fn validate(&self, value: &T, name: &str) -> CoreResult<()>;
fn description(&self) -> String;
// Provided methods
fn and<V: Validator<T>>(self, other: V) -> CompositeValidator<T, Self, V>
where Self: Sized { ... }
fn when<F>(self, condition: F) -> ConditionalValidator<T, Self, F>
where Self: Sized,
F: Fn(&T) -> bool { ... }
}
Expand description
Trait for implementing custom validators
Required Methods§
Sourcefn validate(&self, value: &T, name: &str) -> CoreResult<()>
fn validate(&self, value: &T, name: &str) -> CoreResult<()>
Validate the value and return Ok(()) if valid, or an error if invalid
Sourcefn description(&self) -> String
fn description(&self) -> String
Get a description of what this validator checks
Provided Methods§
Sourcefn and<V: Validator<T>>(self, other: V) -> CompositeValidator<T, Self, V>where
Self: Sized,
fn and<V: Validator<T>>(self, other: V) -> CompositeValidator<T, Self, V>where
Self: Sized,
Chain this validator with another validator