pub trait Validate: Sized {
    type Unvalidated;

    // Required methods
    fn validate(unvalidated: &Self::Unvalidated) -> Result<Self>;
    fn to_unvalidated(&self) -> Self::Unvalidated;
}
Expand description

The Validate trait is used in tandem with the Validatable type in order to provide deferred validation for types.

Trait Contract

Any type V which implement this trait must adhere to the following contract:

  • V and V::Unvalidated are byte-for-byte equivalent.
  • V and V::Unvalidated have equivalent Hash implementations.
  • V and V::Unvalidated must have equivalent Serialize and Deserialize implementation. This means that V and V:Unvalidated have equivalent serialized formats and that you can deserialize a V::Unvalidated from a V that was previously serialized.

Required Associated Types§

source

type Unvalidated

The unvalidated form of some type V

Required Methods§

source

fn validate(unvalidated: &Self::Unvalidated) -> Result<Self>

Attempt to validate a V::Unvalidated and returning a validated V on success

source

fn to_unvalidated(&self) -> Self::Unvalidated

Return the unvalidated form of type V

Implementors§