pub struct SchemaValidator { /* private fields */ }Expand description
Orchestrates schema-level validation for a message type.
§Examples
use mx20022_validate::schema::{SchemaValidator};
use mx20022_validate::schema::constraints::{ConstraintSet, FieldConstraint};
use mx20022_validate::rules::RuleRegistry;
let mut cs = ConstraintSet::new();
cs.add(FieldConstraint::new("/Document/GrpHdr/MsgId", ["MAX_LENGTH"]));
let validator = SchemaValidator::new(cs, RuleRegistry::with_defaults());
let result = validator.validate_field("/Document/GrpHdr/MsgId", "ABC123");
assert!(result.is_valid());Implementations§
Source§impl SchemaValidator
impl SchemaValidator
Sourcepub fn new(constraints: ConstraintSet, registry: RuleRegistry) -> Self
pub fn new(constraints: ConstraintSet, registry: RuleRegistry) -> Self
Create a new SchemaValidator from a constraint set and rule registry.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a SchemaValidator with an empty constraint set and the default rule registry.
Sourcepub fn validate_field(&self, path: &str, value: &str) -> ValidationResult
pub fn validate_field(&self, path: &str, value: &str) -> ValidationResult
Validate a single field value at the given path.
Returns a ValidationResult with any findings from constraints registered
for this path. If no constraints are registered for the path the result is
unconditionally valid.
Sourcepub fn registry_mut(&mut self) -> &mut RuleRegistry
pub fn registry_mut(&mut self) -> &mut RuleRegistry
Access the underlying registry (e.g. to register additional rules).
Sourcepub fn constraints_mut(&mut self) -> &mut ConstraintSet
pub fn constraints_mut(&mut self) -> &mut ConstraintSet
Access the underlying constraint set (e.g. to add constraints at runtime).
Sourcepub fn validate_fields<'a>(
&self,
fields: impl IntoIterator<Item = (&'a str, &'a str)>,
) -> ValidationResult
pub fn validate_fields<'a>( &self, fields: impl IntoIterator<Item = (&'a str, &'a str)>, ) -> ValidationResult
Validate multiple (path, value) pairs and merge all findings.
Auto Trait Implementations§
impl Freeze for SchemaValidator
impl !RefUnwindSafe for SchemaValidator
impl Send for SchemaValidator
impl Sync for SchemaValidator
impl Unpin for SchemaValidator
impl UnsafeUnpin for SchemaValidator
impl !UnwindSafe for SchemaValidator
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