#[non_exhaustive]pub enum ValidationRule {
Show 16 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>,
},
Email,
Phone,
}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 (Non-exhaustive)§
This enum is marked as non-exhaustive
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
use fraiseql_core::validation::ValidationRule;
// Either provide entityId OR (name + description), but not both
let _rule = ValidationRule::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
use fraiseql_core::validation::ValidationRule;
// Provide at least one of: email, phone, address
let _rule = ValidationRule::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
use fraiseql_core::validation::ValidationRule;
// If entityId is provided, then createdAt is required
let _rule = ValidationRule::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
use fraiseql_core::validation::ValidationRule;
// If addressId is missing, then street+city+zip are required
let _rule = ValidationRule::RequiredIfAbsent {
absent_field: "addressId".to_string(),
then_required: vec!["street".to_string(), "city".to_string(), "zip".to_string()],
};Fields
Field must be a valid email address (RFC 5321 practical subset).
Phone
Field must be a valid E.164 international phone number (e.g. +14155552671).
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 moreSource§impl Debug for ValidationRule
impl Debug for ValidationRule
Source§impl<'de> Deserialize<'de> for ValidationRule
impl<'de> Deserialize<'de> for ValidationRule
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ValidationRule
impl PartialEq for ValidationRule
Source§impl Serialize for ValidationRule
impl Serialize for ValidationRule
impl StructuralPartialEq for ValidationRule
Auto Trait Implementations§
impl Freeze for ValidationRule
impl RefUnwindSafe for ValidationRule
impl Send for ValidationRule
impl Sync for ValidationRule
impl Unpin for ValidationRule
impl UnsafeUnpin for ValidationRule
impl UnwindSafe for ValidationRule
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more