Skip to main content

SchemaValidator

Struct SchemaValidator 

Source
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

Source

pub fn new(constraints: ConstraintSet, registry: RuleRegistry) -> Self

Create a new SchemaValidator from a constraint set and rule registry.

Source

pub fn with_defaults() -> Self

Create a SchemaValidator with an empty constraint set and the default rule registry.

Source

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.

Source

pub fn registry_mut(&mut self) -> &mut RuleRegistry

Access the underlying registry (e.g. to register additional rules).

Source

pub fn constraints_mut(&mut self) -> &mut ConstraintSet

Access the underlying constraint set (e.g. to add constraints at runtime).

Source

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§

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.