Skip to main content

SchemeValidator

Trait SchemeValidator 

Source
pub trait SchemeValidator: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn supported_messages(&self) -> &[&str];
    fn validate(&self, xml: &str, message_type: &str) -> ValidationResult;

    // Provided method
    fn validate_typed(
        &self,
        msg: &dyn Any,
        message_type: &str,
    ) -> Option<ValidationResult> { ... }
}
Expand description

A scheme-specific validator for ISO 20022 payment messages.

Provides two validation paths: XML-based (validate) and typed (validate_typed).

§Contract

  • validate must return an empty ValidationResult (no errors, no warnings) for message types not listed in supported_messages.
  • validate_typed returns None for unsupported message types or failed downcasts, and Some(result) for actual validation.
  • Neither method should panic; callers may provide malformed XML or unrecognised types.
  • Implementations should be Send + Sync so they can be stored in Arc<dyn SchemeValidator>.

Required Methods§

Source

fn name(&self) -> &'static str

Human-readable name of the scheme (e.g. "FedNow", "SEPA", "CBPR+").

Source

fn supported_messages(&self) -> &[&str]

Short message type identifiers supported by this scheme.

Each entry is a two-segment dot-separated identifier such as "pacs.008" or "camt.056". The validator should ignore messages whose type does not appear in this list.

Source

fn validate(&self, xml: &str, message_type: &str) -> ValidationResult

Validate raw XML content against this scheme’s rules.

§Migration

This method operates on raw XML strings using fragile string scanning. New callers should use validate_typed which operates on deserialized message structs and catches field-level issues at compile time.

The XML-based path remains available for cases where raw XML is the only input (e.g. CLI validation without prior deserialization), or for checks that inherently require raw XML (message size, AppHdr envelope, control characters).

message_type is the full ISO 20022 message type detected from the XML namespace (e.g. "pacs.008.001.13"). The validator is responsible for deriving the short type and returning early for unsupported types.

Provided Methods§

Source

fn validate_typed( &self, msg: &dyn Any, message_type: &str, ) -> Option<ValidationResult>

Validate a typed (deserialized) message against this scheme’s rules.

msg is a reference to the deserialized message struct (e.g. pacs_008_001_13::Document). Implementations downcast via Any::downcast_ref to the concrete types they support.

message_type is the full ISO 20022 message type (e.g. "pacs.008.001.13"), used to route to the appropriate validation logic.

Returns Some(result) when the validator supports the given message type and the downcast succeeds. Returns None for unsupported message types or failed downcasts, allowing callers to distinguish “valid with no errors” from “not applicable”.

Implementors§