Skip to main content

Rule

Struct Rule 

Source
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

Source

pub fn new(check: impl Fn(&str) -> Option<String> + 'static) -> Self

An arbitrary rule from a closure.

Source

pub fn check(&self, value: &str) -> Option<String>

Applies the rule to value.

Source

pub fn required(message: impl Into<String>) -> Self

Non-empty (leading and trailing whitespace ignored).

Source

pub fn min_len(n: usize, message: impl Into<String>) -> Self

At least n characters (counted as chars, whitespace included).

Source

pub fn max_len(n: usize, message: impl Into<String>) -> Self

At most n characters.

Source

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).

Source

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> 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<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
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.