Skip to main content

Rules

Struct Rules 

Source
pub struct Rules { /* private fields */ }
Expand description

An ordered set of rules for one field.

Order is preserved because it is the order the messages come back in, and a developer who wrote required|email expects to be told about the missing field before the malformed one.

Implementations§

Source§

impl Rules

Source

pub fn new() -> Self

Source

pub fn parse(spec: &str) -> Result<Rules>

Parse Laravel’s pipe/colon syntax: "required|between:1,10|in:a,b,c".

Whitespace around a rule is ignored and empty segments are dropped, so a spec split across lines in a config file still parses.

Source

pub fn rules(&self) -> &[Rule]

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn has(&self, name: &str) -> bool

Whether a rule with this name is in the set. The validator asks this to find nullable, and to decide whether min counts characters or value.

Source

pub fn push(self, rule: Rule) -> Self

Append an already-built rule. The chaining methods below all go through here.

Source

pub fn required(self) -> Self

Source

pub fn nullable(self) -> Self

Source

pub fn string(self) -> Self

Source

pub fn integer(self) -> Self

Source

pub fn numeric(self) -> Self

Source

pub fn boolean(self) -> Self

Source

pub fn email(self) -> Self

Source

pub fn url(self) -> Self

Source

pub fn min(self, bound: impl Into<f64>) -> Self

Source

pub fn max(self, bound: impl Into<f64>) -> Self

Source

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

Source

pub fn size(self, exact: impl Into<f64>) -> Self

Source

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

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

Source

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

Source

pub fn confirmed(self) -> Self

Source

pub fn same(self, other: impl Into<String>) -> Self

Source

pub fn different(self, other: impl Into<String>) -> Self

Source

pub fn alpha(self) -> Self

Source

pub fn alpha_num(self) -> Self

Source

pub fn alpha_dash(self) -> Self

Source

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

Source

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

Source

pub fn date(self) -> Self

Source

pub fn uuid(self) -> Self

Source

pub fn array(self) -> Self

Trait Implementations§

Source§

impl Clone for Rules

Source§

fn clone(&self) -> Rules

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 Rules

Source§

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

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

impl Default for Rules

Source§

fn default() -> Rules

Returns the “default value” for a type. 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 FromStr for Rules

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(spec: &str) -> Result<Rules>

Parses a string s to return a value of this type. Read more
Source§

impl IntoRules for Rules

Source§

impl PartialEq for Rules

Source§

fn eq(&self, other: &Rules) -> 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 Rules

Auto Trait Implementations§

§

impl Freeze for Rules

§

impl RefUnwindSafe for Rules

§

impl Send for Rules

§

impl Sync for Rules

§

impl Unpin for Rules

§

impl UnsafeUnpin for Rules

§

impl UnwindSafe for Rules

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.