MultipleOfRule

Struct MultipleOfRule 

Source
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: T

The divisor

§message: Option<String>

Custom error message

Implementations§

Source§

impl<T> MultipleOfRule<T>

Source

pub fn new(value: T) -> Self

Create a new multiple_of rule.

Source

pub fn message(self, msg: impl Into<String>) -> Self

Set custom error message.

Trait Implementations§

Source§

impl<T: Clone> Clone for MultipleOfRule<T>

Source§

fn clone(&self) -> MultipleOfRule<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for MultipleOfRule<T>

Source§

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

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

impl Rule<f32> for MultipleOfRule<f64>

Source§

fn validate(&self, value: &f32, ctx: &ValidationContext) -> ValidationResult<()>

Validate the value.
Source§

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

Get the rule name for error reporting.
Source§

fn default_message(&self) -> String

Get the default error message.
Source§

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

Get the error code.
Source§

fn is_transform(&self) -> bool

Check if this rule is a transformation (not validation).
Source§

impl Rule<f64> for MultipleOfRule<f64>

Source§

fn validate( &self, value: &f64, _ctx: &ValidationContext, ) -> ValidationResult<()>

Validate the value.
Source§

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

Get the rule name for error reporting.
Source§

fn default_message(&self) -> String

Get the default error message.
Source§

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

Get the error code.
Source§

fn is_transform(&self) -> bool

Check if this rule is a transformation (not validation).
Source§

impl Rule<i32> for MultipleOfRule<i64>

Source§

fn validate(&self, value: &i32, ctx: &ValidationContext) -> ValidationResult<()>

Validate the value.
Source§

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

Get the rule name for error reporting.
Source§

fn default_message(&self) -> String

Get the default error message.
Source§

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

Get the error code.
Source§

fn is_transform(&self) -> bool

Check if this rule is a transformation (not validation).
Source§

impl Rule<i64> for MultipleOfRule<i64>

Source§

fn validate( &self, value: &i64, _ctx: &ValidationContext, ) -> ValidationResult<()>

Validate the value.
Source§

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

Get the rule name for error reporting.
Source§

fn default_message(&self) -> String

Get the default error message.
Source§

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

Get the error code.
Source§

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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.