Skip to main content

Validate

Trait Validate 

Source
pub trait Validate<C, S>
where S: Context, Self: Sized,
{ // Required method fn validate( self, context: impl Into<S>, constraint: &C, ) -> Validation<C, Self>; }
Expand description

The validation function validates whether the given value complies to the specified constraint.

It returns a Validation value that may be used to perform further validations using its combinator methods and or and_then or get the final result by calling the result method.

The context provides additional information to perform the validation, for example a lookup table or some state information. It may also hold parameters needed to provide additional parameters to the error in case of a constraint violation. (see the crate level documentation for more details on how to use the context)

see the crate level documentation for details about how to implement a the Validate trait for custom constraints and custom types.

Required Methods§

Source

fn validate(self, context: impl Into<S>, constraint: &C) -> Validation<C, Self>

Validates this value for being compliant to the specified constraint C in the given context S.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Validate<Pattern, FieldName> for String

Source§

fn validate( self, name: impl Into<FieldName>, constraint: &Pattern, ) -> Validation<Pattern, Self>

Source§

impl<T> Validate<MustDefineRange, RelatedFields> for (T, T)
where T: PartialOrd + Into<Value>,

Source§

fn validate( self, fields: impl Into<RelatedFields>, constraint: &MustDefineRange, ) -> Validation<MustDefineRange, Self>

Source§

impl<T> Validate<MustMatch, RelatedFields> for (T, T)
where T: PartialEq + Into<Value>,

Source§

fn validate( self, fields: impl Into<RelatedFields>, _constraint: &MustMatch, ) -> Validation<MustMatch, Self>

Implementors§