#[non_exhaustive]pub enum ValidationRule {
Pattern(Regex),
Length(usize),
LengthRange {
min: usize,
max: usize,
},
Checksum(ChecksumType),
NumericRange {
min: f64,
max: f64,
},
Enum(Vec<String>),
All(Vec<ValidationRule>),
}Expand description
Validation rule for an operator parameter.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Pattern(Regex)
Pattern matching (pre-compiled regex)
Length(usize)
Exact length
LengthRange
Min and max length
Checksum(ChecksumType)
Checksum algorithm
NumericRange
Range of numeric values
Fields
Enum(Vec<String>)
Value must be one of these options
All(Vec<ValidationRule>)
Composite rule (all must pass)
Implementations§
Source§impl ValidationRule
impl ValidationRule
Sourcepub fn validate(&self, value: &str) -> Result<()>
pub fn validate(&self, value: &str) -> Result<()>
Validate a string value against this rule.
§Errors
Returns FraiseQLError::Validation if the value fails the validation rule,
or if the pattern is an invalid regex.
Sourcepub fn from_json(value: &Value) -> Result<Self>
pub fn from_json(value: &Value) -> Result<Self>
Parse validation rules from JSON (compiled from TOML).
§Errors
Returns FraiseQLError::Validation if the JSON structure does not match any
known validation rule format.
§Panics
Cannot panic: the internal .expect("len checked == 1") is only reached
after verifying rules.len() == 1.
Trait Implementations§
Source§impl Clone for ValidationRule
impl Clone for ValidationRule
Source§fn clone(&self) -> ValidationRule
fn clone(&self) -> ValidationRule
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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