use crate::{Constraint, ConstraintViolationList};
pub trait Validator: Send + Sync {
fn validate_value(
&self,
value: &str,
property_path: &str,
constraints: &[&dyn Constraint],
) -> ConstraintViolationList;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct RecursiveValidator;
impl RecursiveValidator {
#[must_use]
pub const fn new() -> Self {
Self
}
}
impl Validator for RecursiveValidator {
fn validate_value(
&self,
value: &str,
property_path: &str,
constraints: &[&dyn Constraint],
) -> ConstraintViolationList {
let mut violations = ConstraintViolationList::new();
for constraint in constraints {
constraint.validate(value, property_path, &mut violations);
}
violations
}
}
pub trait Validatable {
fn validate(&self, validator: &dyn Validator) -> ConstraintViolationList;
}