#[non_exhaustive]pub struct Rule {
pub id: String,
pub field: Option<String>,
pub kind: RuleKind,
pub contexts: Vec<String>,
pub target_criteria: Option<String>,
pub message: Option<String>,
pub skip_empty: bool,
pub severity: Severity,
}Expand description
One thing a record has to meet, in some contexts, and perhaps only when it fits.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: StringWhat it is known by.
field: Option<String>The field it is about, where the error shows.
kind: RuleKindWhat it asks for.
contexts: Vec<String>When it applies.
target_criteria: Option<String>It applies only to records that meet this.
message: Option<String>What to say, instead of the usual words.
skip_empty: boolWhether an empty field passes, as it does for all but RuleKind::Required.
severity: SeverityHow much not meeting it matters.
Implementations§
Source§impl Rule
impl Rule
Sourcepub fn unique(field: impl Into<String>) -> Self
pub fn unique(field: impl Into<String>) -> Self
No other record can hold the same in the field.
Sourcepub fn range(
field: impl Into<String>,
min: Option<f64>,
max: Option<f64>,
) -> Self
pub fn range( field: impl Into<String>, min: Option<f64>, max: Option<f64>, ) -> Self
The field has to be within these limits.
Sourcepub fn matches(field: impl Into<String>, pattern: impl Into<String>) -> Self
pub fn matches(field: impl Into<String>, pattern: impl Into<String>) -> Self
The field has to match this regular expression.
Sourcepub fn criteria(id: impl Into<String>, expression: impl Into<String>) -> Self
pub fn criteria(id: impl Into<String>, expression: impl Into<String>) -> Self
The record has to meet this expression.
Sourcepub fn contexts(
self,
contexts: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn contexts( self, contexts: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Applies in these contexts, instead of on saving.
Sourcepub fn target_criteria(self, expression: impl Into<String>) -> Self
pub fn target_criteria(self, expression: impl Into<String>) -> Self
Applies only to records that meet this.
Sourcepub fn message(self, message: impl Into<String>) -> Self
pub fn message(self, message: impl Into<String>) -> Self
Says this when it fails. {field} is what a field of the record holds, as it shows, and
{reference.field} the same of the record a reference points to. {$field} is what the
rule’s field is called, {$entity} the entity, {$min} and {$max} the limits.
Sourcepub fn information(self) -> Self
pub fn information(self) -> Self
It goes on, with a note on the field.
Sourcepub fn skip_empty(self, skip: bool) -> Self
pub fn skip_empty(self, skip: bool) -> Self
Whether an empty field passes.