pub struct RangeRule<T> {
pub min: Option<T>,
pub max: Option<T>,
pub exclusive_min: bool,
pub exclusive_max: bool,
pub message: Option<String>,
}Expand description
Numeric range validation rule.
Supports inclusive and exclusive bounds (JSON Schema compatible).
§Example
use skp_validator_rules::numeric::range::RangeRule;
use skp_validator_core::{Rule, ValidationContext};
let rule = RangeRule::<f64>::new().min(0.0).max(100.0);
let ctx = ValidationContext::default();
assert!(rule.validate(&50.0, &ctx).is_ok());
assert!(rule.validate(&-1.0, &ctx).is_err());Fields§
§min: Option<T>Minimum value (inclusive by default)
max: Option<T>Maximum value (inclusive by default)
exclusive_min: boolWhether min is exclusive
exclusive_max: boolWhether max is exclusive
message: Option<String>Custom error message
Implementations§
Source§impl<T> RangeRule<T>
impl<T> RangeRule<T>
Sourcepub fn exclusive_min(self, min: T) -> Self
pub fn exclusive_min(self, min: T) -> Self
Set exclusive minimum.
Sourcepub fn exclusive_max(self, max: T) -> Self
pub fn exclusive_max(self, max: T) -> Self
Set exclusive maximum.
Trait Implementations§
Source§impl Rule<f32> for RangeRule<f32>
impl Rule<f32> for RangeRule<f32>
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 RangeRule<f64>
impl Rule<f64> for RangeRule<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<i128> for RangeRule<i128>
impl Rule<i128> for RangeRule<i128>
Source§fn validate(
&self,
value: &i128,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &i128, _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<i16> for RangeRule<i16>
impl Rule<i16> for RangeRule<i16>
Source§fn validate(
&self,
value: &i16,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &i16, _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 RangeRule<i32>
impl Rule<i32> for RangeRule<i32>
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 RangeRule<i64>
impl Rule<i64> for RangeRule<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).
Source§impl Rule<i8> for RangeRule<i8>
impl Rule<i8> for RangeRule<i8>
Source§fn validate(&self, value: &i8, _ctx: &ValidationContext) -> ValidationResult<()>
fn validate(&self, value: &i8, _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<isize> for RangeRule<isize>
impl Rule<isize> for RangeRule<isize>
Source§fn validate(
&self,
value: &isize,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &isize, _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<u128> for RangeRule<u128>
impl Rule<u128> for RangeRule<u128>
Source§fn validate(
&self,
value: &u128,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &u128, _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<u16> for RangeRule<u16>
impl Rule<u16> for RangeRule<u16>
Source§fn validate(
&self,
value: &u16,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &u16, _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<u32> for RangeRule<u32>
impl Rule<u32> for RangeRule<u32>
Source§fn validate(
&self,
value: &u32,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &u32, _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<u64> for RangeRule<u64>
impl Rule<u64> for RangeRule<u64>
Source§fn validate(
&self,
value: &u64,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &u64, _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<u8> for RangeRule<u8>
impl Rule<u8> for RangeRule<u8>
Source§fn validate(&self, value: &u8, _ctx: &ValidationContext) -> ValidationResult<()>
fn validate(&self, value: &u8, _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<usize> for RangeRule<usize>
impl Rule<usize> for RangeRule<usize>
Source§fn validate(
&self,
value: &usize,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &usize, _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 RangeRule<T>where
T: Freeze,
impl<T> RefUnwindSafe for RangeRule<T>where
T: RefUnwindSafe,
impl<T> Send for RangeRule<T>where
T: Send,
impl<T> Sync for RangeRule<T>where
T: Sync,
impl<T> Unpin for RangeRule<T>where
T: Unpin,
impl<T> UnwindSafe for RangeRule<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