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_product_identifier(&mut self, key: &str) -> &mut Self
pub fn require_product_identifier(&mut self, key: &str) -> &mut Self
Require an EN 18219:2026 clause 5 unique product identifier object.
🚨 This replaces require_gtin for product group
data. Product group records used to carry a bare top-level gtin, and
every plugin required it. They now carry a productIdentifier object
whose shape depends on the scheme that issued it, and the GTIN — when
there is one at all — lives inside it:
{ "productIdentifier": { "scheme": "gs1", "gtin": "09506000134352" } }A plugin still asking for gtin therefore reports “gtin is required”
against data that identifies itself perfectly well. That is not a
hypothetical: it is what every non-textile plugin did once the schemas
moved, and because both host call sites discard a plugin error, the
compliance determination silently stopped being made rather than failing
loudly.
§Why the scheme decides which field is checked
Clause 5.1 offers three schemes as alternatives, not a hierarchy. Only scheme 1 is GS1-keyed, so only scheme 1 has a GTIN; schemes 2 and 3 are self-issuing and carry a URL and a DID respectively. Validating a GTIN unconditionally would reject exactly the passports the identifier work exists to enable, which is the defect this method replaces.
An unrecognised scheme is refused rather than skipped: a scheme string nobody has mapped is where an invented identifier passes unexamined.
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 optional_positive_int(&mut self, key: &str) -> &mut Self
pub fn optional_positive_int(&mut self, key: &str) -> &mut Self
If present (and non-null), the value must be an integer of at least 1.
The optional counterpart of Self::require_positive_int, for a field
whose presence is conditional but whose value, once given, is still
constrained. Deliberately not expressible as
Self::optional_non_negative, which would admit 0 and a fractional
count.
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 require_object(&mut self, key: &str) -> &mut Self
pub fn require_object(&mut self, key: &str) -> &mut Self
Require a present, non-empty object.
The counterpart to require_non_empty_array
for a schema-required field whose value is a nested object — an
unsold-goods report’s entity and financialYear, for instance.
🚨 Presence only. It does not reach inside. present is
input.get(key) with no path traversal, so nothing here can assert a
field within the object; the nested required list is enforced by
schema validation at publish and not at this tier. An empty object is
refused because it satisfies “present” while carrying none of what made
the field required.
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.