catfive 0.2.0

Category-5 fluent, zero-dependency schema and form validation for Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::error::ValidationError;

/// Core trait implemented by any single-value validator.
pub trait Validator<T: ?Sized> {
    /// Validates the given value, returning the first error encountered.
    fn validate(&self, value: &T) -> Result<(), ValidationError> {
        let mut errors = self.validate_all(value);
        if errors.is_empty() {
            Ok(())
        } else {
            Err(errors.remove(0))
        }
    }

    /// Validates the given value, returning all accumulated errors.
    fn validate_all(&self, value: &T) -> Vec<ValidationError>;
}