pub fn contains<'v, V, I>(value: V, item: I) -> Result<'v, ()>where
V: Contains<I>,
Expand description
Contains validator: succeeds when a value contains item
.
This is the dual of omits()
. 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 is equal to an invalid value
If the collection is empty, this validator fails.
ยงExample
use rocket::form::{FromForm, FromFormField};
#[derive(PartialEq, FromFormField)]
enum Pet { Cat, Dog }
#[derive(FromForm)]
struct Foo<'r> {
best_pet: Pet,
#[field(validate = contains(Pet::Cat))]
#[field(validate = contains(&self.best_pet))]
pets: Vec<Pet>,
#[field(validate = contains('/'))]
#[field(validate = contains(&['/', ':']))]
license: &'r str,
#[field(validate = contains("@rust-lang.org"))]
#[field(validate = contains(|c: char| c.to_ascii_lowercase() == 's'))]
rust_lang_email: &'r str,
}