pub trait Validate {
type Error: Debug;
// Required method
fn is_valid(&self) -> Result<(), Self::Error>;
// Provided methods
fn validate(self) -> Result<Valid<Self>, ValidateError<Self, Self::Error>>
where Self: Sized { ... }
fn validate_ref(&self) -> Result<&Valid<Self>, Self::Error>
where Self: Sized { ... }
}Expand description
Represents a type that can be validated
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn validate(self) -> Result<Valid<Self>, ValidateError<Self, Self::Error>>where
Self: Sized,
fn validate(self) -> Result<Valid<Self>, ValidateError<Self, Self::Error>>where
Self: Sized,
Validates the value
If value is valid, returns Ok(validated_value) wrapped into type guard Valid<T>, otherwise returns
Err(err) containing the error and the invalid value.
Sourcefn validate_ref(&self) -> Result<&Valid<Self>, Self::Error>where
Self: Sized,
fn validate_ref(&self) -> Result<&Valid<Self>, Self::Error>where
Self: Sized,
Validates the value by reference
If value is valid, returns &Valid<Self>, otherwise returns validation error