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.
OneOf
String field must equal one of the listed values (case-sensitive).
Regex
String field must match the given Rust regex. summary is a
short human description (“ISO-3166 alpha-2”) shown in the error.
Length
String / array field length bounds (Unicode chars for strings, len for arrays).
ExactlyOne
Exactly one of the named fields must be present + non-null.
AtLeastOne
At least one of the named fields must be present + non-null.
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
eval: fn(&JsonObject) -> Result<(), FieldViolation>