serenade_validator/
validator.rs1use crate::{Constraint, ConstraintViolationList};
4
5pub trait Validator: Send + Sync {
7 fn validate_value(
9 &self,
10 value: &str,
11 property_path: &str,
12 constraints: &[&dyn Constraint],
13 ) -> ConstraintViolationList;
14}
15
16#[derive(Debug, Default, Clone, Copy)]
18pub struct RecursiveValidator;
19
20impl RecursiveValidator {
21 #[must_use]
23 pub const fn new() -> Self {
24 Self
25 }
26}
27
28impl Validator for RecursiveValidator {
29 fn validate_value(
30 &self,
31 value: &str,
32 property_path: &str,
33 constraints: &[&dyn Constraint],
34 ) -> ConstraintViolationList {
35 let mut violations = ConstraintViolationList::new();
36 for constraint in constraints {
37 constraint.validate(value, property_path, &mut violations);
38 }
39 violations
40 }
41}
42
43pub trait Validatable {
45 fn validate(&self, validator: &dyn Validator) -> ConstraintViolationList;
47}