[][src]Trait gotham_formdata::validate::Validator

pub trait Validator<T: ?Sized> {
    type Err;
    pub fn validate(self, data: &T) -> Result<(), Self::Err>;
}

This trait allows data of type T to be verified against custom criteria.

Example:

use gotham_formdata::FormData;

fn validate_password(password: &String) -> Result<(), &'static str> {
	if password.len() < 8 {
		return Err("Password is too short");
		}
	Ok(())
}

#[derive(FormData)]
struct LoginData {
	username: String,
	#[validate(validator = validate_password)]
	password: String
}

Associated Types

type Err[src]

The error returned when validation failed.

Loading content...

Required methods

pub fn validate(self, data: &T) -> Result<(), Self::Err>[src]

Performs the validation.

Loading content...

Implementations on Foreign Types

impl<T: ?Sized> Validator<T> for ()[src]

Convert () into an allways accepting validator.

type Err = Infallible

Loading content...

Implementors

impl<'a, D, T> Validator<D> for ExpectedValidator<'a, T> where
    D: PartialEq<T>, 
[src]

type Err = UnexpectedValueError

impl<'re, T: AsRef<str>> Validator<T> for RegexValidator<'re>[src]

type Err = RegexMismatchError<'re>

impl<F, Err, T: ?Sized> Validator<T> for F where
    F: Fn(&T) -> Result<(), Err>, 
[src]

Convert any function with the correct signature into a validator.

type Err = Err

impl<I, T> Validator<T> for MaxValidator<I> where
    I: Debug + Display + PartialOrd,
    T: Clone + Into<I>, 
[src]

type Err = ValueTooLargeError<I>

impl<I, T> Validator<T> for MinValidator<I> where
    I: Debug + Display + PartialOrd,
    T: Clone + Into<I>, 
[src]

type Err = ValueTooSmallError<I>

impl<T: AsRef<str>> Validator<T> for MaxLengthValidator[src]

type Err = ValueTooLongError

impl<T: AsRef<str>> Validator<T> for MinLengthValidator[src]

type Err = ValueTooShortError

impl<T: ?Sized, V: Validator<T>, W: Validator<T>> Validator<T> for CombinedValidator<T, V, W>[src]

type Err = Either<V::Err, W::Err>

Loading content...