Function rocket::form::validate::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,
}