[−][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 ) })) } 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<F>(function: F) -> Self where
F: Fn(&Value, &Key) -> Result<(), ValidationError<Key>> + 'static, [src]
F: Fn(&Value, &Key) -> Result<(), ValidationError<Key>> + 'static,
Create a new ValidatorFn.
Trait Implementations
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, 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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,