Trait Validator

Source
pub trait Validator<T> {
    // Required methods
    fn instructions(&self) -> String;
    fn validate(&self, value: &T) -> Result<(), String>;
}
Expand description

A Validator is a type that can validate a value of type T.

Required Methods§

Source

fn instructions(&self) -> String

A human-readable string that describes the validation to be performed.

Example: “Value must be a positive integer”

Source

fn validate(&self, value: &T) -> Result<(), String>

Validate a value of type T.

If possible, the error should indicate how the caller might fix the problem.

Example: if the value must be a prime number, the error message might indicate the nearest prime number to the value that was given.

Implementors§