Skip to main content

Rule

Struct Rule 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§id: String

What it is known by.

§field: Option<String>

The field it is about, where the error shows.

§kind: RuleKind

What 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: bool

Whether an empty field passes, as it does for all but RuleKind::Required.

§severity: Severity

How much not meeting it matters.

Implementations§

Source§

impl Rule

Source

pub fn new(id: impl Into<String>, kind: RuleKind) -> Self

A rule about the whole record.

Source

pub fn on(field: impl Into<String>, kind: RuleKind) -> Self

A rule about a field.

Source

pub fn required(field: impl Into<String>) -> Self

The field has to have something in it.

Source

pub fn unique(field: impl Into<String>) -> Self

No other record can hold the same in the field.

Source

pub fn range( field: impl Into<String>, min: Option<f64>, max: Option<f64>, ) -> Self

The field has to be within these limits.

Source

pub fn matches(field: impl Into<String>, pattern: impl Into<String>) -> Self

The field has to match this regular expression.

Source

pub fn criteria(id: impl Into<String>, expression: impl Into<String>) -> Self

The record has to meet this expression.

Source

pub fn contexts( self, contexts: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Applies in these contexts, instead of on saving.

Source

pub fn target_criteria(self, expression: impl Into<String>) -> Self

Applies only to records that meet this.

Source

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.

Source

pub fn severity(self, severity: Severity) -> Self

How much not meeting it matters.

Source

pub fn warning(self) -> Self

People are told, and can go on anyway.

Source

pub fn information(self) -> Self

It goes on, with a note on the field.

Source

pub fn skip_empty(self, skip: bool) -> Self

Whether an empty field passes.

Trait Implementations§

Source§

impl Clone for Rule

Source§

fn clone(&self) -> Rule

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Rule

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Rule

§

impl !Send for Rule

§

impl !Sync for Rule

§

impl !UnwindSafe for Rule

§

impl Freeze for Rule

§

impl Unpin for Rule

§

impl UnsafeUnpin for Rule

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.