rocket::form::validate

Function neq

Source
pub fn neq<'v, A, B>(a: &A, b: B) -> Result<'v, ()>
where A: PartialEq<B>,
Expand description

Negative equality validator: succeeds exactly when a != b, using PartialEq.

On error, returns a validation error with the following message:

value is equal to an invalid value

ยงExample

use rocket::form::{FromForm, FromFormField};

#[derive(FromFormField, PartialEq)]
enum Kind {
    Car,
    Truck
}

#[derive(FromForm)]
struct Foo<'r> {
    #[field(validate = neq("Bob Marley"))]
    name: &'r str,
    #[field(validate = neq(Kind::Car))]
    vehicle: Kind,
    #[field(validate = neq(&[5, 7, 8]))]
    numbers: Vec<usize>,
}