Skip to main content

Validator

Trait Validator 

Source
pub trait Validator: Send + Sync {
    // Required methods
    fn validate(
        &self,
        attribute: &str,
        value: Option<&Value>,
        errors: &mut Errors,
    );
    fn name(&self) -> &str;
    fn options(&self) -> &ValidatorOptions;

    // Provided method
    fn validate_with_attrs(
        &self,
        attribute: &str,
        value: Option<&Value>,
        _attrs: &dyn Fn(&str) -> Option<Value>,
        errors: &mut Errors,
    ) { ... }
}
Expand description

A validation rule that can check a value and report errors.

Required Methods§

Source

fn validate(&self, attribute: &str, value: Option<&Value>, errors: &mut Errors)

Validates a single attribute value, adding any produced errors.

Source

fn name(&self) -> &str

Returns the validator’s display name.

Source

fn options(&self) -> &ValidatorOptions

Returns the common runtime options for this validator.

Provided Methods§

Source

fn validate_with_attrs( &self, attribute: &str, value: Option<&Value>, _attrs: &dyn Fn(&str) -> Option<Value>, errors: &mut Errors, )

Validates a single attribute with access to sibling attributes when needed.

Implementors§