Function rocket::form::validate::omits

source ·
pub fn omits<'v, V, I>(value: V, item: I) -> Result<'v, ()>
where V: Contains<I>,
Expand description

Omits validator: succeeds when a value does not contains item. error message.

This is the dual of contains(). The value must implement Contains<I> where I is the type of the item. See Contains for supported types and items.

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

value contains a disallowed item

If the collection is empty, this validator succeeds.


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

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

struct Foo<'r> {
    #[field(validate = omits(Pet::Cat))]
    pets: Vec<Pet>,
    #[field(validate = omits('@'))]
    not_email: &'r str,
    #[field(validate = omits(""))]
    non_gmail_email: &'r str,