pub enum ValidationRule {
Show 14 variants
Required,
Pattern {
pattern: String,
message: Option<String>,
},
Length {
min: Option<usize>,
max: Option<usize>,
},
Range {
min: Option<i64>,
max: Option<i64>,
},
Enum {
values: Vec<String>,
},
Checksum {
algorithm: String,
},
CrossField {
field: String,
operator: String,
},
Conditional {
condition: String,
then_rules: Vec<Box<ValidationRule>>,
},
All(Vec<ValidationRule>),
Any(Vec<ValidationRule>),
OneOf {
fields: Vec<String>,
},
AnyOf {
fields: Vec<String>,
},
ConditionalRequired {
if_field_present: String,
then_required: Vec<String>,
},
RequiredIfAbsent {
absent_field: String,
then_required: Vec<String>,
},
}Expand description
A validation rule that can be applied to a field.
Rules define constraints on field values and are evaluated during input validation. Multiple rules can be combined on a single field.
Variants§
Required
Field is required (non-null) and must have a value.
Pattern
Field value must match a regular expression pattern.
Fields
Length
String field length constraints.
Range
Numeric field range constraints.
Enum
Field value must be one of allowed enum values.
Checksum
Checksum validation for structured data.
CrossField
Cross-field validation rule.
Fields
Conditional
Conditional validation - only validate if condition is met.
Fields
then_rules: Vec<Box<ValidationRule>>Rules to apply if condition is true.
All(Vec<ValidationRule>)
Composite rule - all rules must pass.
Any(Vec<ValidationRule>)
Composite rule - at least one rule must pass.
OneOf
Exactly one field from the set must be provided (mutually exclusive).
Useful for “create or reference” patterns where you must provide EITHER an ID to reference an existing entity OR the fields to create a new one, but not both.
§Example
// Either provide entityId OR (name + description), but not both
OneOf { fields: vec!["name".to_string(), "description".to_string()] }AnyOf
At least one field from the set must be provided.
Useful for optional but not-all-empty patterns.
§Example
// Provide at least one of: email, phone, address
AnyOf { fields: vec!["email".to_string(), "phone".to_string(), "address".to_string()] }ConditionalRequired
If a field is present, then other fields are required.
Used for conditional requirements based on presence of another field.
§Example
// If entityId is provided, then createdAt is required
ConditionalRequired {
if_field_present: "entityId".to_string(),
then_required: vec!["createdAt".to_string()]
}Fields
RequiredIfAbsent
If a field is absent/null, then other fields are required.
Used for “provide this OR that” patterns at the object level.
§Example
// If addressId is missing, then street+city+zip are required
RequiredIfAbsent {
absent_field: "addressId".to_string(),
then_required: vec!["street".to_string(), "city".to_string(), "zip".to_string()]
}Implementations§
Source§impl ValidationRule
impl ValidationRule
Sourcepub const fn is_required(&self) -> bool
pub const fn is_required(&self) -> bool
Check if this is a required field validation.
Sourcepub fn description(&self) -> String
pub fn description(&self) -> String
Get a human-readable description of this rule.
Trait Implementations§
Source§impl Clone for ValidationRule
impl Clone for ValidationRule
Source§fn clone(&self) -> ValidationRule
fn clone(&self) -> ValidationRule
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more