Skip to main content

Validator

Trait Validator 

Source
pub trait Validator {
    type Output;

    // Required methods
    fn validate(&self, value: Input<'_>) -> Option<Self::Output>;
    fn description(&self) -> String;
}
Expand description

A check of one value that returns it in the type it was checked as.

use utopia_validators::{Input, Port, Validator};

assert_eq!(Port.validate(Input::Str(b"6379")), Some(6379));
assert_eq!(Port.validate(Input::Int(70000)), None);
assert_eq!(Port.description(), "Value must be a port between 1 and 65535");
use Utopia\Validator\Port;

$port = new Port();
var_dump($port->isValid('6379'));  // true
var_dump($port->isValid(70000));   // false

Required Associated Types§

Source

type Output

The type of a value that passed.

Required Methods§

Source

fn validate(&self, value: Input<'_>) -> Option<Self::Output>

The value, when it is valid.

PHP: isValid().

Source

fn description(&self) -> String

What a valid value is, to tell whoever sent one that is not.

PHP: getDescription().

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl Validator for Boolean

Source§

impl Validator for Float

Source§

impl Validator for Hostname

Source§

impl Validator for Integer

An integer within the bounds, as an int or as text.

PHP: new Integer(loose: true, $bits, $unsigned).

Source§

impl Validator for Port

Source§

impl Validator for Range

Source§

impl Validator for Text

Source§

impl Validator for WhiteList<'_>