ferro-rs 0.2.9

A Laravel-inspired web framework for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//! Validation rule trait.

use serde_json::Value;

/// A validation rule that can be applied to a field.
pub trait Rule: Send + Sync {
    /// Validate the given value.
    ///
    /// Returns `Ok(())` if validation passes, or `Err(message)` if it fails.
    fn validate(&self, field: &str, value: &Value, data: &Value) -> Result<(), String>;

    /// Get the rule name for error messages.
    fn name(&self) -> &'static str;
}