[−][src]Struct form_validation::ValidatorFn
Function to perform validation on a form field.
Example
use form_validation::{Validation, ValidationError, ValidatorFn}; let v: ValidatorFn<i32, String> = ValidatorFn::new(|value, key: &String| { if value < &0 { let value_clone = *value; Err(ValidationError::new(key.clone()).with_message(move |key| { format!( "The value of {} ({}) cannot be less than 0", key, value_clone ) }).into()) // convert into ValidationErrors } else { Ok(()) } }); let key = "field1".to_string(); assert!(v.validate_value(&20, &key).is_ok()); assert!(v.validate_value(&-1, &key).is_err()); assert_eq!( "The value of field1 (-1) cannot be less than 0", v.validate_value(&-1, &key).unwrap_err().to_string() );
Implementations
impl<Value, Key> ValidatorFn<Value, Key>
[src]
pub fn new<C>(closure: C) -> Self where
C: Fn(&Value, &Key) -> Result<(), ValidationErrors<Key>> + 'static,
[src]
C: Fn(&Value, &Key) -> Result<(), ValidationErrors<Key>> + 'static,
Create a new ValidatorFn
.
Trait Implementations
impl<Value, Key> Clone for ValidatorFn<Value, Key>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<Value, Key> Debug for ValidatorFn<Value, Key>
[src]
impl<C, Value, Key> From<C> for ValidatorFn<Value, Key> where
C: Fn(&Value, &Key) -> Result<(), ValidationErrors<Key>> + 'static,
[src]
C: Fn(&Value, &Key) -> Result<(), ValidationErrors<Key>> + 'static,
impl<Value, Key> From<ValidatorFn<Value, Key>> for AsyncValidatorFn<Value, Key> where
Key: Clone + PartialEq + 'static,
Value: Clone + PartialEq + 'static,
[src]
Key: Clone + PartialEq + 'static,
Value: Clone + PartialEq + 'static,
fn from(validator_fn: ValidatorFn<Value, Key>) -> Self
[src]
impl<Value, Key> PartialEq<ValidatorFn<Value, Key>> for ValidatorFn<Value, Key>
[src]
impl<Value, Key> Validation<Value, Key> for ValidatorFn<Value, Key> where
Key: Clone + PartialEq,
[src]
Key: Clone + PartialEq,
fn validate_value(
&self,
value: &Value,
key: &Key
) -> Result<(), ValidationErrors<Key>>
[src]
&self,
value: &Value,
key: &Key
) -> Result<(), ValidationErrors<Key>>
Auto Trait Implementations
impl<Value, Key> !RefUnwindSafe for ValidatorFn<Value, Key>
impl<Value, Key> !Send for ValidatorFn<Value, Key>
impl<Value, Key> !Sync for ValidatorFn<Value, Key>
impl<Value, Key> Unpin for ValidatorFn<Value, Key>
impl<Value, Key> !UnwindSafe for ValidatorFn<Value, Key>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,