Skip to main content

Validatable

Trait Validatable 

Source
pub trait Validatable {
    // Required methods
    fn validate(&self) -> Result<(), ValidationError>;
    fn validation_rules() -> Vec<(&'static str, Vec<Box<dyn Rule>>)>;
}
Expand description

Trait for types that can validate themselves using declarative rules.

This trait is typically derived using #[derive(Validate)]:

use ferro_rs::Validate;

#[derive(Validate)]
struct CreateUserRequest {
    #[validate(required, email)]
    email: String,

    #[validate(required, min(8))]
    password: String,
}

// Usage
let request = CreateUserRequest { ... };
request.validate()?;

Required Methods§

Source

fn validate(&self) -> Result<(), ValidationError>

Validate the struct against its declared rules.

Returns Ok(()) if validation passes, or Err(ValidationError) with all validation errors collected.

Source

fn validation_rules() -> Vec<(&'static str, Vec<Box<dyn Rule>>)>

Get the static rule definitions for this type.

Returns a list of (field_name, rules) tuples that can be used for introspection (e.g., by ferro-mcp).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§