Skip to main content

Validator

Struct Validator 

Source
pub struct Validator<'a> { /* private fields */ }
Expand description

Fluent per-field validator. See module docs.

Implementations§

Source§

impl<'a> Validator<'a>

Source

pub fn new(input: &'a PluginInput) -> Self

Source

pub fn require_str(&mut self, key: &str) -> &mut Self

Require a present, non-empty string.

Source

pub fn require_enum(&mut self, key: &str, allowed: &[&str]) -> &mut Self

Require a string field whose value is one of allowed.

Source

pub fn require_gtin(&mut self, key: &str) -> &mut Self

Require a 14-digit GS1 GTIN string with a valid check digit.

Source

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.

Source

pub fn require_country(&mut self, key: &str) -> &mut Self

Require a recognized ISO 3166-1 alpha-2 country code.

Source

pub fn require_positive(&mut self, key: &str) -> &mut Self

Require a present, finite number greater than 0.

Source

pub fn require_non_negative(&mut self, key: &str) -> &mut Self

Require a present, finite number greater than or equal to 0.

Source

pub fn require_pct(&mut self, key: &str) -> &mut Self

Require a present, finite number in [0, 100].

Source

pub fn require_positive_int(&mut self, key: &str) -> &mut Self

Require a present non-negative integer that is at least 1.

Source

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.

Source

pub fn require_bool(&mut self, key: &str) -> &mut Self

Require a present boolean.

Source

pub fn require_non_empty_array(&mut self, key: &str) -> &mut Self

Require a present, non-empty array.

Source

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.

Source

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].

Source

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.

Source

pub fn optional_non_negative(&mut self, key: &str) -> &mut Self

If present (and non-null), the value must be a finite number ≥ 0.

Source

pub fn finish(&mut self) -> Result<(), PluginError>

Finish validation, returning every collected error at once.

Auto Trait Implementations§

§

impl<'a> Freeze for Validator<'a>

§

impl<'a> RefUnwindSafe for Validator<'a>

§

impl<'a> Send for Validator<'a>

§

impl<'a> Sync for Validator<'a>

§

impl<'a> Unpin for Validator<'a>

§

impl<'a> UnsafeUnpin for Validator<'a>

§

impl<'a> UnwindSafe for Validator<'a>

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> 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, 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.