pub trait Validator<T> {
// Required methods
fn validate(&self, value: &T, name: &str) -> Result<(), CoreError>;
fn description(&self) -> String;
// Provided methods
fn and<V>(self, other: V) -> CompositeValidator<T, Self, V>
where V: Validator<T>,
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) -> Result<(), CoreError>
fn validate(&self, value: &T, name: &str) -> Result<(), CoreError>
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>(self, other: V) -> CompositeValidator<T, Self, V>
fn and<V>(self, other: V) -> CompositeValidator<T, Self, V>
Chain this validator with another validator
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".