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 error, returns a validation error with the following message:

value does not match expected value


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

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

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>,