pub struct Len<const MIN: usize, const MAX: usize = { usize::MAX }>;Expand description
Requires the length of a string or collection to be in a range.
Both ends are inclusive. Strings count characters, collections items
(see Length). The code of the violation is the name of the
validator: len, min_len (MinLen) or max_len (MaxLen). It
has the parameters min and max (if they are set).
use deser_validate::{Len, MaxLen, Validator};
assert!(Len::<1, 3>::validate("abc").is_ok());
assert_eq!(
Len::<1, 3>::validate("abcd").unwrap_err().message(),
"length must be between 1 and 3"
);
assert!(MaxLen::<2>::validate(&vec![1, 2, 3]).is_err());Trait Implementations§
Auto Trait Implementations§
impl<const MIN: usize, const MAX: usize> Freeze for Len<MIN, MAX>
impl<const MIN: usize, const MAX: usize> RefUnwindSafe for Len<MIN, MAX>
impl<const MIN: usize, const MAX: usize> Send for Len<MIN, MAX>
impl<const MIN: usize, const MAX: usize> Sync for Len<MIN, MAX>
impl<const MIN: usize, const MAX: usize> Unpin for Len<MIN, MAX>
impl<const MIN: usize, const MAX: usize> UnsafeUnpin for Len<MIN, MAX>
impl<const MIN: usize, const MAX: usize> UnwindSafe for Len<MIN, MAX>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more