Validator

Trait Validator 

Source
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§

Source

fn validate(&self, value: &T, name: &str) -> CoreResult<()>

Validate the value and return Ok(()) if valid, or an error if invalid

Source

fn description(&self) -> String

Get a description of what this validator checks

Provided Methods§

Source

fn and<V: Validator<T>>(self, other: V) -> CompositeValidator<T, Self, V>
where Self: Sized,

Chain this validator with another validator

Source

fn when<F>(self, condition: F) -> ConditionalValidator<T, Self, F>
where Self: Sized, F: Fn(&T) -> bool,

Create a conditional validator that only applies when a condition is met

Implementors§

Source§

impl<S, T, D> Validator<ArrayBase<S, D>> for ArrayValidator<T, D>
where S: Data<Elem = T>, T: Clone, D: Dimension,

Source§

impl<T> Validator<T> for RangeValidator<T>
where T: PartialOrd + Copy + Display,

Source§

impl<T, F> Validator<T> for FunctionValidator<T, F>
where F: Fn(&T, &str) -> CoreResult<()>,

Source§

impl<T, V1, V2> Validator<T> for CompositeValidator<T, V1, V2>
where V1: Validator<T>, V2: Validator<T>,

Source§

impl<T, V, F> Validator<T> for ConditionalValidator<T, V, F>
where V: Validator<T>, F: Fn(&T) -> bool,

Source§

impl<T: 'static> Validator<T> for MultiValidator<T>