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
impl Rules
pub fn new() -> Self
Sourcepub fn parse(spec: &str) -> Result<Rules>
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.
pub fn rules(&self) -> &[Rule]
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Sourcepub fn has(&self, name: &str) -> bool
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.
Sourcepub fn push(self, rule: Rule) -> Self
pub fn push(self, rule: Rule) -> Self
Append an already-built rule. The chaining methods below all go through here.
pub fn required(self) -> Self
pub fn nullable(self) -> Self
pub fn string(self) -> Self
pub fn integer(self) -> Self
pub fn numeric(self) -> Self
pub fn boolean(self) -> Self
pub fn email(self) -> Self
pub fn url(self) -> Self
pub fn min(self, bound: impl Into<f64>) -> Self
pub fn max(self, bound: impl Into<f64>) -> Self
pub fn between(self, low: impl Into<f64>, high: impl Into<f64>) -> Self
pub fn size(self, exact: impl Into<f64>) -> Self
Sourcepub fn one_of<S: Into<String>>(
self,
values: impl IntoIterator<Item = S>,
) -> Self
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.
pub fn not_in<S: Into<String>>( self, values: impl IntoIterator<Item = S>, ) -> Self
pub fn confirmed(self) -> Self
pub fn same(self, other: impl Into<String>) -> Self
pub fn different(self, other: impl Into<String>) -> Self
pub fn alpha(self) -> Self
pub fn alpha_num(self) -> Self
pub fn alpha_dash(self) -> Self
pub fn starts_with<S: Into<String>>( self, prefixes: impl IntoIterator<Item = S>, ) -> Self
pub fn ends_with<S: Into<String>>( self, suffixes: impl IntoIterator<Item = S>, ) -> Self
pub fn date(self) -> Self
pub fn uuid(self) -> Self
pub fn array(self) -> Self
Trait Implementations§
Source§impl FromIterator<Rule> for Rules
impl FromIterator<Rule> for Rules
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> 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