pub enum Constraint {
Show 17 variants
Range {
min: f64,
max: f64,
},
Pattern(String),
AllowedValues(Vec<String>),
Length {
min: usize,
max: usize,
},
Precision {
decimal_places: usize,
},
Unique,
NotNull,
Custom(String),
ArrayElements(Box<Constraint>),
ArraySize {
min: usize,
max: usize,
},
Statistical(StatisticalConstraints),
Temporal(TimeConstraints),
Shape(ShapeConstraints),
And(Vec<Constraint>),
Or(Vec<Constraint>),
Not(Box<Constraint>),
If {
condition: Box<Constraint>,
then_constraint: Box<Constraint>,
else_constraint: Option<Box<Constraint>>,
},
}Expand description
Validation constraints for data fields
Variants§
Range
Value must be within range (inclusive)
Pattern(String)
String must match pattern
AllowedValues(Vec<String>)
Value must be one of the allowed values
Length
String length constraints
Precision
Numeric precision constraints
Unique
Uniqueness constraint
NotNull
Non-null constraint
Custom(String)
Custom validation rule
ArrayElements(Box<Constraint>)
Array element constraints
ArraySize
Array size constraints
Statistical(StatisticalConstraints)
Statistical constraints for numeric data
Temporal(TimeConstraints)
Time-based constraints
Shape(ShapeConstraints)
Matrix/array shape constraints
And(Vec<Constraint>)
Logical AND of multiple constraints - all must pass
Or(Vec<Constraint>)
Logical OR of multiple constraints - at least one must pass
Not(Box<Constraint>)
Logical NOT of a constraint - must not pass
If
Conditional constraint - if condition passes, then constraint must pass
Fields
condition: Box<Constraint>then_constraint: Box<Constraint>else_constraint: Option<Box<Constraint>>Implementations§
Source§impl Constraint
impl Constraint
Sourcepub fn all_of(constraints: Vec<Constraint>) -> Self
pub fn all_of(constraints: Vec<Constraint>) -> Self
Create a constraint that requires all of the given constraints to pass
Sourcepub fn any_of(constraints: Vec<Constraint>) -> Self
pub fn any_of(constraints: Vec<Constraint>) -> Self
Create a constraint that requires at least one of the given constraints to pass
Sourcepub fn not(constraint: Constraint) -> Self
pub fn not(constraint: Constraint) -> Self
Create a constraint that requires the given constraint to not pass
Sourcepub fn if_then(
condition: Constraint,
then_constraint: Constraint,
else_constraint: Option<Constraint>,
) -> Self
pub fn if_then( condition: Constraint, then_constraint: Constraint, else_constraint: Option<Constraint>, ) -> Self
Create a conditional constraint
Sourcepub fn and(self, other: Constraint) -> Self
pub fn and(self, other: Constraint) -> Self
Chain this constraint with another using AND logic
Sourcepub fn or(self, other: Constraint) -> Self
pub fn or(self, other: Constraint) -> Self
Chain this constraint with another using OR logic
Trait Implementations§
Source§impl Clone for Constraint
impl Clone for Constraint
Source§fn clone(&self) -> Constraint
fn clone(&self) -> Constraint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Constraint
impl Debug for Constraint
Source§impl<'de> Deserialize<'de> for Constraint
impl<'de> Deserialize<'de> for Constraint
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 Constraint
impl PartialEq for Constraint
Source§impl Serialize for Constraint
impl Serialize for Constraint
impl StructuralPartialEq for Constraint
Auto Trait Implementations§
impl Freeze for Constraint
impl RefUnwindSafe for Constraint
impl Send for Constraint
impl Sync for Constraint
impl Unpin for Constraint
impl UnwindSafe for Constraint
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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
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 moreSource§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.