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) -> Rule
pub fn new(check: impl Fn(&str) -> Option<String> + 'static) -> Rule
An arbitrary rule from a closure.
Sourcepub fn required(message: impl Into<String>) -> Rule
pub fn required(message: impl Into<String>) -> Rule
Non-empty (leading and trailing whitespace ignored).
Sourcepub fn min_len(n: usize, message: impl Into<String>) -> Rule
pub fn min_len(n: usize, message: impl Into<String>) -> Rule
At least n characters (counted as chars, whitespace included).
Sourcepub fn email(message: impl Into<String>) -> Rule
pub fn email(message: impl Into<String>) -> Rule
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>) -> Rule
pub fn all(rules: impl IntoIterator<Item = Rule>) -> Rule
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.