pub struct NumericalityValidator {
pub only_integer: bool,
pub greater_than: Option<f64>,
pub greater_than_or_equal_to: Option<f64>,
pub less_than: Option<f64>,
pub less_than_or_equal_to: Option<f64>,
pub equal_to: Option<f64>,
pub other_than: Option<f64>,
pub odd: bool,
pub even: bool,
pub allow_nil: bool,
pub message: Option<String>,
/* private fields */
}Expand description
Validates that an attribute contains a numeric value and optional comparisons.
Fields§
§only_integer: boolRestricts the value to integers.
greater_than: Option<f64>Requires the value to be greater than the provided bound.
greater_than_or_equal_to: Option<f64>Requires the value to be greater than or equal to the provided bound.
less_than: Option<f64>Requires the value to be less than the provided bound.
less_than_or_equal_to: Option<f64>Requires the value to be less than or equal to the provided bound.
equal_to: Option<f64>Requires the value to equal the provided bound.
other_than: Option<f64>Requires the value to differ from the provided bound.
odd: boolRequires the value to be odd.
even: boolRequires the value to be even.
allow_nil: boolSkips validation when the attribute value is missing or null.
message: Option<String>Custom message used for non-numeric input.
Implementations§
Source§impl NumericalityValidator
impl NumericalityValidator
Sourcepub fn allow_blank(self) -> Self
pub fn allow_blank(self) -> Self
Skips validation when the attribute value is blank.
Sourcepub fn on(self, contexts: Vec<ValidationContext>) -> Self
pub fn on(self, contexts: Vec<ValidationContext>) -> Self
Restricts the validator to the provided contexts.
Sourcepub fn if_cond<F>(self, cond: F) -> Self
pub fn if_cond<F>(self, cond: F) -> Self
Runs the validator only when the predicate returns true.
Sourcepub fn unless_cond<F>(self, cond: F) -> Self
pub fn unless_cond<F>(self, cond: F) -> Self
Skips the validator when the predicate returns true.
Sourcepub fn only_integer(self) -> Self
pub fn only_integer(self) -> Self
Restricts values to integers.
Sourcepub fn greater_than(self, bound: f64) -> Self
pub fn greater_than(self, bound: f64) -> Self
Requires the value to be greater than bound.
Sourcepub fn greater_than_or_equal_to(self, bound: f64) -> Self
pub fn greater_than_or_equal_to(self, bound: f64) -> Self
Requires the value to be greater than or equal to bound.
Sourcepub fn less_than_or_equal_to(self, bound: f64) -> Self
pub fn less_than_or_equal_to(self, bound: f64) -> Self
Requires the value to be less than or equal to bound.
Sourcepub fn other_than(self, bound: f64) -> Self
pub fn other_than(self, bound: f64) -> Self
Requires the value to differ from bound.
Trait Implementations§
Source§impl Clone for NumericalityValidator
impl Clone for NumericalityValidator
Source§fn clone(&self) -> NumericalityValidator
fn clone(&self) -> NumericalityValidator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NumericalityValidator
impl Debug for NumericalityValidator
Source§impl Default for NumericalityValidator
impl Default for NumericalityValidator
Source§fn default() -> NumericalityValidator
fn default() -> NumericalityValidator
Auto Trait Implementations§
impl Freeze for NumericalityValidator
impl !RefUnwindSafe for NumericalityValidator
impl Send for NumericalityValidator
impl Sync for NumericalityValidator
impl Unpin for NumericalityValidator
impl UnsafeUnpin for NumericalityValidator
impl !UnwindSafe for NumericalityValidator
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more