pub struct Rule(/* private fields */);Expand description
One field’s validation rule: returns Some(message) if the value is invalid,
None if it passes.
Implementations§
Source§impl Rule
impl Rule
Sourcepub fn new(check: impl Fn(&str) -> Option<String> + 'static) -> Self
pub fn new(check: impl Fn(&str) -> Option<String> + 'static) -> Self
An arbitrary rule from a closure.
Sourcepub fn required(message: impl Into<String>) -> Self
pub fn required(message: impl Into<String>) -> Self
Non-empty (leading and trailing whitespace ignored).
Sourcepub fn min_len(n: usize, message: impl Into<String>) -> Self
pub fn min_len(n: usize, message: impl Into<String>) -> Self
At least n characters (counted as chars, whitespace included).
Sourcepub fn email(message: impl Into<String>) -> Self
pub fn email(message: impl Into<String>) -> Self
A plausible e-mail shape: local@domain, a non-empty local part, and a domain
containing a dot that is not flush against the edges (a heuristic, not the RFC).
Sourcepub fn all(rules: impl IntoIterator<Item = Rule>) -> Self
pub fn all(rules: impl IntoIterator<Item = Rule>) -> Self
Combines rules: the first to fail, in order, wins.
Auto Trait Implementations§
impl !RefUnwindSafe for Rule
impl !Send for Rule
impl !Sync for Rule
impl !UnwindSafe for Rule
impl Freeze for Rule
impl Unpin for Rule
impl UnsafeUnpin for Rule
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