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_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 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 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.