Validate

Trait Validate 

Source
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§

Source

type Error: Debug

Validation error

Required Methods§

Source

fn is_valid(&self) -> Result<(), Self::Error>

Checks whether value is valid

Returns Ok(()) if it’s valid, otherwise returns Err(err)

Provided Methods§

Source

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.

Source

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

Implementations on Foreign Types§

Source§

impl<T: Validate> Validate for &T

Source§

type Error = <T as Validate>::Error

Source§

fn is_valid(&self) -> Result<(), Self::Error>

Implementors§