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)); // falseRequired Associated Types§
Required Methods§
Sourcefn validate(&self, value: Input<'_>) -> Option<Self::Output>
fn validate(&self, value: Input<'_>) -> Option<Self::Output>
The value, when it is valid.
PHP: isValid().
Sourcefn description(&self) -> String
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".