[][src]Struct form_validation::ValidationError

pub struct ValidationError<Key> {
    pub key: Key,
    pub type_id: &'static str,
    // some fields omitted
}

An error associated with a form field.

Fields

key: Key

The key for the field that this validation error is associated with.

type_id: &'static str

An identifier for the type of error this is.

Implementations

impl<Key> ValidationError<Key>[src]

pub fn new(key: Key, type_id: &'static str) -> Self[src]

Create a new ValidationError with a generic message, and specify the type_id which allows the error type to be identified programatically.

pub fn message<S: Into<String>>(self, message: S) -> Self[src]

Factory method to set the message for this error.

pub fn with_message<F: Fn(&Key) -> String + 'static>(
    self,
    message_fn: F
) -> Self
[src]

Factory method to set the message for this error from a function that returns a String.

Example

use form_validation::ValidationError;

let value = -10;
let error = ValidationError::new("field1", "NOT_LESS_THAN_0")
    .with_message(move |key| {
        format!(
           "The value of {} ({}) cannot be less than 0",
            key, value)
});

assert_eq!("The value of field1 (-10) cannot be less than 0", error.to_string());
assert_eq!("NOT_LESS_THAN_0", error.type_id);

Trait Implementations

impl<Key> Clone for ValidationError<Key> where
    Key: Clone
[src]

impl<Key> Debug for ValidationError<Key> where
    Key: Debug
[src]

impl<Key> Display for ValidationError<Key>[src]

impl<Key> Error for ValidationError<Key> where
    Key: Debug
[src]

impl<Key> From<ValidationError<Key>> for ValidationErrors<Key> where
    Key: Clone + PartialEq
[src]

impl<Key> PartialEq<ValidationError<Key>> for ValidationError<Key> where
    Key: PartialEq
[src]

Auto Trait Implementations

impl<Key> !RefUnwindSafe for ValidationError<Key>

impl<Key> !Send for ValidationError<Key>

impl<Key> !Sync for ValidationError<Key>

impl<Key> Unpin for ValidationError<Key> where
    Key: Unpin

impl<Key> !UnwindSafe for ValidationError<Key>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,