rocket::form::validate

Function range

Source
pub fn range<'v, V, R>(value: &V, range: R) -> Result<'v, ()>
where V: TryInto<isize> + Copy, R: RangeBounds<isize>,
Expand description

Integer range validator: succeeds when an integer value is within a range.

The value must be an integer type that implement TryInto<isize> + Copy. On error, returns an OutOfRange error.

ยงExample

use rocket::form::FromForm;

#[derive(FromForm)]
struct Foo {
    #[field(validate = range(0..))]
    non_negative: isize,
    #[field(validate = range(18..=130))]
    maybe_adult: u8,
}