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
impl RuleRegistry
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a registry pre-populated with all built-in rules.
Built-in rules included:
IBAN_CHECK— IBAN format + mod-97BIC_CHECK— BIC/SWIFT formatCURRENCY_CHECK— ISO 4217 currency codeCOUNTRY_CHECK— ISO 3166-1 alpha-2 country codeLEI_CHECK— ISO 17442 LEI format + mod-97AMOUNT_FORMAT— ISO 20022 decimal amount formatDATETIME_CHECK— ISO 8601 datetimeDATE_CHECK— ISO 8601 date
Sourcepub fn register(&mut self, rule: Box<dyn Rule>)
pub fn register(&mut self, rule: Box<dyn Rule>)
Register a rule. If a rule with the same ID already exists it is replaced.
Sourcepub fn validate_field(
&self,
value: &str,
path: &str,
rule_ids: &[&str],
) -> Vec<ValidationError>
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());Sourcepub fn validate_all(&self, value: &str, path: &str) -> Vec<ValidationError>
pub fn validate_all(&self, value: &str, path: &str) -> Vec<ValidationError>
Run all registered rules against value at path.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RuleRegistry
impl !RefUnwindSafe for RuleRegistry
impl Send for RuleRegistry
impl Sync for RuleRegistry
impl Unpin for RuleRegistry
impl UnsafeUnpin for RuleRegistry
impl !UnwindSafe for RuleRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more