Skip to main content

Range

Struct Range 

Source
pub struct Range<const MIN: i128, const MAX: i128>;
Expand description

Requires an integer to be in a range.

Both ends are inclusive. The code of the violation is the name of the validator: range, min (Min) or max (Max). It has the parameters min and max (if they are set).

use deser_validate::{Min, Range, Validator};

assert!(Range::<1, 65535>::validate(&80u16).is_ok());
assert_eq!(
    Range::<1, 65535>::validate(&0u16).unwrap_err().message(),
    "must be between 1 and 65535"
);
assert!(Min::<1>::validate(&0u32).is_err());

Trait Implementations§

Source§

impl<T: Integer + ?Sized, const MIN: i128, const MAX: i128> Validator<T> for Range<MIN, MAX>

Source§

fn validate(value: &T) -> Result<(), Violation>

Validates the value.

Auto Trait Implementations§

§

impl<const MIN: i128, const MAX: i128> Freeze for Range<MIN, MAX>

§

impl<const MIN: i128, const MAX: i128> RefUnwindSafe for Range<MIN, MAX>

§

impl<const MIN: i128, const MAX: i128> Send for Range<MIN, MAX>

§

impl<const MIN: i128, const MAX: i128> Sync for Range<MIN, MAX>

§

impl<const MIN: i128, const MAX: i128> Unpin for Range<MIN, MAX>

§

impl<const MIN: i128, const MAX: i128> UnsafeUnpin for Range<MIN, MAX>

§

impl<const MIN: i128, const MAX: i128> UnwindSafe for Range<MIN, MAX>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.