RangeRule

Struct RangeRule 

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

Whether min is exclusive

§exclusive_max: bool

Whether max is exclusive

§message: Option<String>

Custom error message

Implementations§

Source§

impl<T> RangeRule<T>

Source

pub fn new() -> Self

Create a new range rule.

Source

pub fn min(self, min: T) -> Self

Set minimum value (inclusive).

Source

pub fn max(self, max: T) -> Self

Set maximum value (inclusive).

Source

pub fn exclusive_min(self, min: T) -> Self

Set exclusive minimum.

Source

pub fn exclusive_max(self, max: T) -> Self

Set exclusive maximum.

Source

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

Set custom error message.

Trait Implementations§

Source§

impl<T: Clone> Clone for RangeRule<T>

Source§

fn clone(&self) -> RangeRule<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 RangeRule<T>

Source§

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

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

impl<T> Default for RangeRule<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Rule<f32> for RangeRule<f32>

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 RangeRule<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<i128> for RangeRule<i128>

Source§

fn validate( &self, value: &i128, _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<i16> for RangeRule<i16>

Source§

fn validate( &self, value: &i16, _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 RangeRule<i32>

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 RangeRule<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).
Source§

impl Rule<i8> for RangeRule<i8>

Source§

fn validate(&self, value: &i8, _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<isize> for RangeRule<isize>

Source§

fn validate( &self, value: &isize, _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<u128> for RangeRule<u128>

Source§

fn validate( &self, value: &u128, _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<u16> for RangeRule<u16>

Source§

fn validate( &self, value: &u16, _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<u32> for RangeRule<u32>

Source§

fn validate( &self, value: &u32, _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<u64> for RangeRule<u64>

Source§

fn validate( &self, value: &u64, _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<u8> for RangeRule<u8>

Source§

fn validate(&self, value: &u8, _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<usize> for RangeRule<usize>

Source§

fn validate( &self, value: &usize, _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 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> 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.