rocket::form::validate

Function dbg_eq

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

Debug equality validator: like eq() but mentions b in the error message.

The is identical to eq() except that b must be Debug and the error message is as follows, where $b is the Debug representation of b:

value must be $b

ยงExample

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

#[derive(PartialEq, Debug, Clone, Copy, FromFormField)]
enum Pet { Cat, Dog }

#[derive(FromForm)]
struct Foo {
    number: usize,
    #[field(validate = dbg_eq(self.number))]
    confirm_num: usize,
    #[field(validate = dbg_eq(Pet::Dog))]
    best_pet: Pet,
}