Skip to main content

Rule

Enum Rule 

Source
pub enum Rule {
Show 25 variants Required, Nullable, String, Integer, Numeric, Boolean, Email, Url, Min(f64), Max(f64), Between(f64, f64), Size(f64), In(Vec<String>), NotIn(Vec<String>), Confirmed, Same(String), Different(String), Alpha, AlphaNum, AlphaDash, StartsWith(Vec<String>), EndsWith(Vec<String>), Date, Uuid, Array,
}
Expand description

One validation rule, with its parameters already parsed.

This is the single internal representation: the string parser and the builder are two front doors onto the same enum.

Variants§

§

Required

The field must be present and not blank.

§

Nullable

An explicit null is allowed, and skips the remaining rules.

§

String

§

Integer

§

Numeric

§

Boolean

§

Email

§

Url

§

Min(f64)

Minimum length for a string, value for a number, item count for an array.

§

Max(f64)

Maximum length for a string, value for a number, item count for an array.

§

Between(f64, f64)

Inclusive range, measured the same way as Rule::Min.

§

Size(f64)

Exact length, value, or item count.

§

In(Vec<String>)

§

NotIn(Vec<String>)

§

Confirmed

A <field>_confirmation field must be present and equal.

§

Same(String)

Must equal another field.

§

Different(String)

Must differ from another field.

§

Alpha

§

AlphaNum

§

AlphaDash

§

StartsWith(Vec<String>)

§

EndsWith(Vec<String>)

§

Date

A YYYY-MM-DD calendar date.

§

Uuid

§

Array

Implementations§

Source§

impl Rule

Source

pub fn name(&self) -> &'static str

The name this rule is written as in the string syntax, which is also the key used to look up its message and any per-field override.

Source

pub fn required() -> Rules

Source

pub fn nullable() -> Rules

Source

pub fn string() -> Rules

Source

pub fn integer() -> Rules

Source

pub fn numeric() -> Rules

Source

pub fn boolean() -> Rules

Source

pub fn email() -> Rules

Source

pub fn url() -> Rules

Source

pub fn min(bound: impl Into<f64>) -> Rules

Source

pub fn max(bound: impl Into<f64>) -> Rules

Source

pub fn between(low: impl Into<f64>, high: impl Into<f64>) -> Rules

Source

pub fn size(exact: impl Into<f64>) -> Rules

Source

pub fn one_of<S: Into<String>>(values: impl IntoIterator<Item = S>) -> Rules

The builder spelling of in:a,b,c; in is a Rust keyword.

Source

pub fn not_in<S: Into<String>>(values: impl IntoIterator<Item = S>) -> Rules

Source

pub fn confirmed() -> Rules

Source

pub fn same(other: impl Into<String>) -> Rules

Source

pub fn different(other: impl Into<String>) -> Rules

Source

pub fn alpha() -> Rules

Source

pub fn alpha_num() -> Rules

Source

pub fn alpha_dash() -> Rules

Source

pub fn starts_with<S: Into<String>>( prefixes: impl IntoIterator<Item = S>, ) -> Rules

Source

pub fn ends_with<S: Into<String>>( suffixes: impl IntoIterator<Item = S>, ) -> Rules

Source

pub fn date() -> Rules

Source

pub fn uuid() -> Rules

Source

pub fn array() -> Rules

Trait Implementations§

Source§

impl Clone for Rule

Source§

fn clone(&self) -> Rule

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromIterator<Rule> for Rules

Source§

fn from_iter<I: IntoIterator<Item = Rule>>(rules: I) -> Self

Creates a value from an iterator. Read more
Source§

impl IntoRules for Rule

Source§

impl PartialEq for Rule

Source§

fn eq(&self, other: &Rule) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Rule

Auto Trait Implementations§

§

impl Freeze for Rule

§

impl RefUnwindSafe for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnsafeUnpin for Rule

§

impl UnwindSafe 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.