pub struct MultipleOfRule<T> {
pub value: T,
pub message: Option<String>,
}Expand description
Multiple of validation rule - value must be divisible by the specified number.
§Example
use skp_validator_rules::numeric::multiple_of::MultipleOfRule;
use skp_validator_core::{Rule, ValidationContext};
let rule = MultipleOfRule::new(5.0);
let ctx = ValidationContext::default();
assert!(rule.validate(&10.0, &ctx).is_ok());
assert!(rule.validate(&7.0, &ctx).is_err());Fields§
§value: TThe divisor
message: Option<String>Custom error message
Implementations§
Trait Implementations§
Source§impl<T: Clone> Clone for MultipleOfRule<T>
impl<T: Clone> Clone for MultipleOfRule<T>
Source§fn clone(&self) -> MultipleOfRule<T>
fn clone(&self) -> MultipleOfRule<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for MultipleOfRule<T>
impl<T: Debug> Debug for MultipleOfRule<T>
Source§impl Rule<f32> for MultipleOfRule<f64>
impl Rule<f32> for MultipleOfRule<f64>
Source§fn validate(&self, value: &f32, ctx: &ValidationContext) -> ValidationResult<()>
fn validate(&self, value: &f32, ctx: &ValidationContext) -> ValidationResult<()>
Validate the value.
Source§fn default_message(&self) -> String
fn default_message(&self) -> String
Get the default error message.
Source§fn validate_at(
&self,
value: &T,
path: &FieldPath,
ctx: &ValidationContext,
) -> Result<(), ValidationErrors>
fn validate_at( &self, value: &T, path: &FieldPath, ctx: &ValidationContext, ) -> Result<(), ValidationErrors>
Validate the value with a field path for error reporting.
Source§fn error_code(&self) -> String
fn error_code(&self) -> String
Get the error code.
Source§fn is_transform(&self) -> bool
fn is_transform(&self) -> bool
Check if this rule is a transformation (not validation).
Source§impl Rule<f64> for MultipleOfRule<f64>
impl Rule<f64> for MultipleOfRule<f64>
Source§fn validate(
&self,
value: &f64,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &f64, _ctx: &ValidationContext, ) -> ValidationResult<()>
Validate the value.
Source§fn default_message(&self) -> String
fn default_message(&self) -> String
Get the default error message.
Source§fn validate_at(
&self,
value: &T,
path: &FieldPath,
ctx: &ValidationContext,
) -> Result<(), ValidationErrors>
fn validate_at( &self, value: &T, path: &FieldPath, ctx: &ValidationContext, ) -> Result<(), ValidationErrors>
Validate the value with a field path for error reporting.
Source§fn error_code(&self) -> String
fn error_code(&self) -> String
Get the error code.
Source§fn is_transform(&self) -> bool
fn is_transform(&self) -> bool
Check if this rule is a transformation (not validation).
Source§impl Rule<i32> for MultipleOfRule<i64>
impl Rule<i32> for MultipleOfRule<i64>
Source§fn validate(&self, value: &i32, ctx: &ValidationContext) -> ValidationResult<()>
fn validate(&self, value: &i32, ctx: &ValidationContext) -> ValidationResult<()>
Validate the value.
Source§fn default_message(&self) -> String
fn default_message(&self) -> String
Get the default error message.
Source§fn validate_at(
&self,
value: &T,
path: &FieldPath,
ctx: &ValidationContext,
) -> Result<(), ValidationErrors>
fn validate_at( &self, value: &T, path: &FieldPath, ctx: &ValidationContext, ) -> Result<(), ValidationErrors>
Validate the value with a field path for error reporting.
Source§fn error_code(&self) -> String
fn error_code(&self) -> String
Get the error code.
Source§fn is_transform(&self) -> bool
fn is_transform(&self) -> bool
Check if this rule is a transformation (not validation).
Source§impl Rule<i64> for MultipleOfRule<i64>
impl Rule<i64> for MultipleOfRule<i64>
Source§fn validate(
&self,
value: &i64,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &i64, _ctx: &ValidationContext, ) -> ValidationResult<()>
Validate the value.
Source§fn default_message(&self) -> String
fn default_message(&self) -> String
Get the default error message.
Source§fn validate_at(
&self,
value: &T,
path: &FieldPath,
ctx: &ValidationContext,
) -> Result<(), ValidationErrors>
fn validate_at( &self, value: &T, path: &FieldPath, ctx: &ValidationContext, ) -> Result<(), ValidationErrors>
Validate the value with a field path for error reporting.
Source§fn error_code(&self) -> String
fn error_code(&self) -> String
Get the error code.
Source§fn is_transform(&self) -> bool
fn is_transform(&self) -> bool
Check if this rule is a transformation (not validation).
Auto Trait Implementations§
impl<T> Freeze for MultipleOfRule<T>where
T: Freeze,
impl<T> RefUnwindSafe for MultipleOfRule<T>where
T: RefUnwindSafe,
impl<T> Send for MultipleOfRule<T>where
T: Send,
impl<T> Sync for MultipleOfRule<T>where
T: Sync,
impl<T> Unpin for MultipleOfRule<T>where
T: Unpin,
impl<T> UnwindSafe for MultipleOfRule<T>where
T: UnwindSafe,
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