pub trait Validate {
type Invalidity: Invalidity;
fn validate(&self) -> ValidationResult<Self::Invalidity>;
}
Expand description
A trait for validating types
Validation is expected to be an expensive operation that should only be invoked when crossing boundaries between independent components.
Required Associated Types
sourcetype Invalidity: Invalidity
type Invalidity: Invalidity
Invalidity objectives
Required Methods
sourcefn validate(&self) -> ValidationResult<Self::Invalidity>
fn validate(&self) -> ValidationResult<Self::Invalidity>
Perform the validation
Errors
Returns Err
with the collected invalidities if one or more
validations failed.
Implementations on Foreign Types
sourceimpl<'a, V> Validate for &'a Vwhere
V: Validate + ?Sized,
impl<'a, V> Validate for &'a Vwhere
V: Validate + ?Sized,
Validate
is implemented for any reference of a type
that implements Validate
.
type Invalidity = <V as Validate>::Invalidity
fn validate(&self) -> ValidationResult<Self::Invalidity>
sourceimpl<V> Validate for Option<V>where
V: Validate,
impl<V> Validate for Option<V>where
V: Validate,
Validate Some
or otherwise implicitly evaluate to Ok
in case of None
If the absence of an optional value is considered a validation error this must be checked separately.
type Invalidity = <V as Validate>::Invalidity
fn validate(&self) -> ValidationResult<Self::Invalidity>
sourceimpl<V> Validate for [V]where
V: Validate,
impl<V> Validate for [V]where
V: Validate,
Validate all elements of a slice