pub fn one_of<'v, V, I, R>(value: V, items: R) -> Result<'v, ()>
Expand description
Contains one of validator: succeeds when a value contains at least one item
in an items
iterator.
The value must implement Contains<I>
where I
is the type of
the item
. The iterator must be Clone
. See Contains
for supported
types and items. The item must be Debug
.
On error, returns a InvalidChoice
error with the debug representation
of each item in items
.
§Example
use rocket::form::FromForm;
#[derive(FromForm)]
struct Foo<'r> {
#[field(validate = one_of(&[3, 5, 7]))]
single_digit_primes: Vec<u8>,
#[field(validate = one_of(" \t\n".chars()))]
has_space_char: &'r str,
#[field(validate = one_of(" \t\n".chars()).and_then(msg!("no spaces")))]
no_space: &'r str,
}