Skip to main content

RuleRegistry

Struct RuleRegistry 

Source
pub struct RuleRegistry { /* private fields */ }
Expand description

A registry of named validation rules.

Rules are stored by their Rule::id. When multiple rules share an ID the last one registered wins (use unique IDs unless intentional override is needed).

§Examples

use mx20022_validate::rules::RuleRegistry;

let registry = RuleRegistry::with_defaults();
let errors = registry.validate_field("GB82WEST12345698765432", "/path/iban", &["IBAN_CHECK"]);
assert!(errors.is_empty());

Implementations§

Source§

impl RuleRegistry

Source

pub fn new() -> Self

Create an empty registry.

Source

pub fn with_defaults() -> Self

Create a registry pre-populated with all built-in rules.

Built-in rules included:

  • IBAN_CHECK — IBAN format + mod-97
  • BIC_CHECK — BIC/SWIFT format
  • CURRENCY_CHECK — ISO 4217 currency code
  • COUNTRY_CHECK — ISO 3166-1 alpha-2 country code
  • LEI_CHECK — ISO 17442 LEI format + mod-97
  • AMOUNT_FORMAT — ISO 20022 decimal amount format
  • DATETIME_CHECK — ISO 8601 datetime
  • DATE_CHECK — ISO 8601 date
Source

pub fn register(&mut self, rule: Box<dyn Rule>)

Register a rule. If a rule with the same ID already exists it is replaced.

Source

pub fn get(&self, rule_id: &str) -> Option<&dyn Rule>

Look up a registered rule by ID.

Source

pub fn validate_field( &self, value: &str, path: &str, rule_ids: &[&str], ) -> Vec<ValidationError>

Run a specific subset of rules (identified by rule_ids) against value at path and return all findings.

Rules whose IDs are not present in the registry are silently skipped.

§Examples
use mx20022_validate::rules::RuleRegistry;

let registry = RuleRegistry::with_defaults();
let errors = registry.validate_field("NOT_AN_IBAN", "/doc/iban", &["IBAN_CHECK"]);
assert!(!errors.is_empty());
Source

pub fn validate_all(&self, value: &str, path: &str) -> Vec<ValidationError>

Run all registered rules against value at path.

Trait Implementations§

Source§

impl Default for RuleRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.