Skip to main content

Validator

Trait Validator 

Source
pub trait Validator: Send + Sync {
    // Required methods
    fn validate(&self, value: &Value, field: &str) -> ValidationResult;
    fn is_required(&self) -> bool;
    fn is_nullable(&self) -> bool;

    // Provided method
    fn set_fail_fast(&mut self, _fail_fast: bool) { ... }
}
Expand description

The trait implemented by all validators.

Validators operate on serde_json::Value so the same rules can be reused for JSON APIs, configuration files, and form data.

Required Methods§

Source

fn validate(&self, value: &Value, field: &str) -> ValidationResult

Validate value at the given field path.

Source

fn is_required(&self) -> bool

Whether the field is required.

Source

fn is_nullable(&self) -> bool

Whether the field may be explicitly null.

Provided Methods§

Source

fn set_fail_fast(&mut self, _fail_fast: bool)

Set fail-fast mode for this validator and its children.

Trait Implementations§

Source§

impl Validator for Box<dyn Validator>

Allow boxed validators to be used anywhere a Validator is expected (e.g. when building schemas dynamically).

Source§

fn validate(&self, value: &Value, field: &str) -> ValidationResult

Validate value at the given field path.
Source§

fn is_required(&self) -> bool

Whether the field is required.
Source§

fn is_nullable(&self) -> bool

Whether the field may be explicitly null.
Source§

fn set_fail_fast(&mut self, fail_fast: bool)

Set fail-fast mode for this validator and its children.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Validator for Box<dyn Validator>

Allow boxed validators to be used anywhere a Validator is expected (e.g. when building schemas dynamically).

Source§

fn validate(&self, value: &Value, field: &str) -> ValidationResult

Source§

fn is_required(&self) -> bool

Source§

fn is_nullable(&self) -> bool

Source§

fn set_fail_fast(&mut self, fail_fast: bool)

Implementors§