Skip to main content

Rule

Enum Rule 

Source
pub enum Rule {
    Range {
        field: &'static str,
        min: Option<f64>,
        max: Option<f64>,
    },
    OneOf {
        field: &'static str,
        values: &'static [&'static str],
    },
    Regex {
        field: &'static str,
        pattern: &'static str,
        summary: &'static str,
    },
    Length {
        field: &'static str,
        min: Option<usize>,
        max: Option<usize>,
    },
    ExactlyOne {
        fields: &'static [&'static str],
    },
    AtLeastOne {
        fields: &'static [&'static str],
    },
    All(&'static [Rule]),
    Any(&'static [Rule]),
    Not(&'static Rule),
    Custom {
        name: &'static str,
        summary: &'static str,
        eval: fn(&JsonObject) -> Result<(), FieldViolation>,
    },
}
Expand description

Declarative validation rule. Built once per skill (typically as a &'static [Rule]) so there’s no per-call allocation cost.

Variants§

§

Range

Numeric field must satisfy min <= value <= max. Either bound is optional. Works for any field that parses as f64.

Fields

§field: &'static str
§

OneOf

String field must equal one of the listed values (case-sensitive).

Fields

§field: &'static str
§values: &'static [&'static str]
§

Regex

String field must match the given Rust regex. summary is a short human description (“ISO-3166 alpha-2”) shown in the error.

Fields

§field: &'static str
§pattern: &'static str
§summary: &'static str
§

Length

String / array field length bounds (Unicode chars for strings, len for arrays).

Fields

§field: &'static str
§

ExactlyOne

Exactly one of the named fields must be present + non-null.

Fields

§fields: &'static [&'static str]
§

AtLeastOne

At least one of the named fields must be present + non-null.

Fields

§fields: &'static [&'static str]
§

All(&'static [Rule])

Conjunction — every sub-rule must pass.

§

Any(&'static [Rule])

Disjunction — at least one sub-rule must pass. Failures are reported only when EVERY branch fails (aggregated).

§

Not(&'static Rule)

Negation — the inner rule must NOT match. Useful as the dual of OneOf.

§

Custom

Custom validator. Receives the full args object, returns Ok or one FieldViolation. Use sparingly — declarative variants are preferred because crate::describe can render them.

Fields

§name: &'static str

Stable identifier shown in error output and introspection.

§summary: &'static str

One-line summary shown in introspection.

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

Auto Trait Implementations§

§

impl Freeze for Rule

§

impl RefUnwindSafe for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnsafeUnpin for Rule

§

impl UnwindSafe 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more