Skip to main content

ValidationRule

Enum ValidationRule 

Source
pub enum ValidationRule {
    MinLength {
        field_name: String,
        min: usize,
        error_message: String,
    },
    MaxLength {
        field_name: String,
        max: usize,
        error_message: String,
    },
    Pattern {
        field_name: String,
        pattern: String,
        error_message: String,
    },
    MinValue {
        field_name: String,
        min: f64,
        error_message: String,
    },
    MaxValue {
        field_name: String,
        max: f64,
        error_message: String,
    },
    Email {
        field_name: String,
        error_message: String,
    },
    Url {
        field_name: String,
        error_message: String,
    },
    FieldsEqual {
        field_names: Vec<String>,
        error_message: String,
        target_field: Option<String>,
    },
    DateRange {
        start_field: String,
        end_field: String,
        error_message: String,
        target_field: Option<String>,
    },
    NumericRange {
        min_field: String,
        max_field: String,
        error_message: String,
        target_field: Option<String>,
    },
    ValidatorRef {
        field_name: String,
        validator_id: String,
        params: Value,
        error_message: String,
    },
}
Expand description

Validation rule types for client-side validation (Phase 2-A)

These rules enable client-side validation for better UX, while server-side validation remains mandatory for security.

§Security Note

Client-side validation is for UX enhancement only and MUST NOT be relied upon for security. Server-side validation is always required.

§Design Principle

All validation rules are declarative and type-safe. We do NOT use JavaScript expressions to prevent arbitrary code execution vulnerabilities. Instead, each rule type has specific parameters that are validated in Rust.

Variants§

§

MinLength

Minimum length validation for string fields

Fields

§field_name: String

Field name to validate

§min: usize

Minimum required length

§error_message: String

Error message to display when validation fails

§

MaxLength

Maximum length validation for string fields

Fields

§field_name: String

Field name to validate

§max: usize

Maximum allowed length

§error_message: String

Error message to display when validation fails

§

Pattern

Regex pattern validation for string fields

Fields

§field_name: String

Field name to validate

§pattern: String

Regex pattern to match (must be valid regex)

§error_message: String

Error message to display when validation fails

§

MinValue

Minimum value validation for numeric fields

Fields

§field_name: String

Field name to validate

§min: f64

Minimum allowed value

§error_message: String

Error message to display when validation fails

§

MaxValue

Maximum value validation for numeric fields

Fields

§field_name: String

Field name to validate

§max: f64

Maximum allowed value

§error_message: String

Error message to display when validation fails

§

Email

Email format validation

Fields

§field_name: String

Field name to validate

§error_message: String

Error message to display when validation fails

§

Url

URL format validation

Fields

§field_name: String

Field name to validate

§error_message: String

Error message to display when validation fails

§

FieldsEqual

Cross-field equality validation (e.g., password confirmation)

Fields

§field_names: Vec<String>

Field names to compare for equality

§error_message: String

Error message to display when validation fails

§target_field: Option<String>

Target field for error display (None = non-field error)

§

DateRange

Date range validation (end_date >= start_date)

Fields

§start_field: String

Start date field name

§end_field: String

End date field name

§error_message: String

Error message to display when validation fails

§target_field: Option<String>

Target field for error display

§

NumericRange

Numeric range validation (max >= min)

Fields

§min_field: String

Minimum value field name

§max_field: String

Maximum value field name

§error_message: String

Error message to display when validation fails

§target_field: Option<String>

Target field for error display

§

ValidatorRef

Reference to reinhardt-validators Validator

Fields

§field_name: String

Field name to validate

§validator_id: String

Validator identifier (e.g., “email”, “url”, “min_length”)

§params: Value

Validator parameters as JSON Example: {“min”: 8, “max”: 20} for MinMaxLengthValidator

§error_message: String

Error message to display when validation fails

Trait Implementations§

Source§

impl Clone for ValidationRule

Source§

fn clone(&self) -> ValidationRule

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 Debug for ValidationRule

Source§

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

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

impl<'de> Deserialize<'de> for ValidationRule

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ValidationRule

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,