pub struct Validator<'a> { /* private fields */ }Expand description
Fluent per-field validator. See module docs.
Implementations§
Source§impl<'a> Validator<'a>
impl<'a> Validator<'a>
pub fn new(input: &'a PluginInput) -> Self
Sourcepub fn require_str(&mut self, key: &str) -> &mut Self
pub fn require_str(&mut self, key: &str) -> &mut Self
Require a present, non-empty string.
Sourcepub fn require_enum(&mut self, key: &str, allowed: &[&str]) -> &mut Self
pub fn require_enum(&mut self, key: &str, allowed: &[&str]) -> &mut Self
Require a string field whose value is one of allowed.
Sourcepub fn require_gtin(&mut self, key: &str) -> &mut Self
pub fn require_gtin(&mut self, key: &str) -> &mut Self
Require a 14-digit GS1 GTIN string with a valid check digit.
Sourcepub fn require_country(&mut self, key: &str) -> &mut Self
pub fn require_country(&mut self, key: &str) -> &mut Self
Require a recognized ISO 3166-1 alpha-2 country code.
Sourcepub fn require_positive(&mut self, key: &str) -> &mut Self
pub fn require_positive(&mut self, key: &str) -> &mut Self
Require a present, finite number greater than 0.
Sourcepub fn require_non_negative(&mut self, key: &str) -> &mut Self
pub fn require_non_negative(&mut self, key: &str) -> &mut Self
Require a present, finite number greater than or equal to 0.
Sourcepub fn require_pct(&mut self, key: &str) -> &mut Self
pub fn require_pct(&mut self, key: &str) -> &mut Self
Require a present, finite number in [0, 100].
Sourcepub fn require_positive_int(&mut self, key: &str) -> &mut Self
pub fn require_positive_int(&mut self, key: &str) -> &mut Self
Require a present non-negative integer that is at least 1.
Sourcepub fn require_bool(&mut self, key: &str) -> &mut Self
pub fn require_bool(&mut self, key: &str) -> &mut Self
Require a present boolean.
Sourcepub fn require_non_empty_array(&mut self, key: &str) -> &mut Self
pub fn require_non_empty_array(&mut self, key: &str) -> &mut Self
Require a present, non-empty array.
Sourcepub fn optional_pct(&mut self, key: &str) -> &mut Self
pub fn optional_pct(&mut self, key: &str) -> &mut Self
If present (and non-null), the value must be a finite number in [0, 100].
Sourcepub fn optional_range(&mut self, key: &str, min: f64, max: f64) -> &mut Self
pub fn optional_range(&mut self, key: &str, min: f64, max: f64) -> &mut Self
If present (and non-null), the value must be a finite number in [min, max].
For a field that is optional (its absence is meaningful) but must be bounded when supplied — e.g. a 0–10 repairability score that gates a verdict only when present.
Sourcepub fn optional_non_negative(&mut self, key: &str) -> &mut Self
pub fn optional_non_negative(&mut self, key: &str) -> &mut Self
If present (and non-null), the value must be a finite number ≥ 0.
Sourcepub fn finish(&mut self) -> Result<(), PluginError>
pub fn finish(&mut self) -> Result<(), PluginError>
Finish validation, returning every collected error at once.