Function rocket::form::validate::eq

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

Equality validator: succeeds exactly when a == b, using PartialEq.

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

value does not match expected value

Example

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

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

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