Skip to main content

mx20022/
lib.rs

1//! ISO 20022 financial message toolkit.
2//!
3//! `mx20022` is an umbrella crate that re-exports the four workspace
4//! components needed to read, write, validate, and translate
5//! ISO 20022 messages and SWIFT MT messages:
6//!
7//! - [`model`] — strongly-typed message structs generated from the
8//!   official XSD schemas (`pacs`, `pain`, `camt`, `head`).
9//! - [`parse`] — XML deserialization, serialization, and envelope
10//!   message-type detection.
11//! - [`validate`] — field-level rule, schema, and scheme (`FedNow` / SEPA /
12//!   CBPR+) validation.
13//! - [`translate`] — bidirectional MT ↔ MX translation for the supported
14//!   message pairs (MT103 ↔ pacs.008, MT202 ↔ pacs.009, MT940 ↔ camt.053).
15//!
16//! See the per-crate docs for full API surface; the [`prelude`] re-exports
17//! the items most users need for typical workflows.
18//!
19//! # Quick start: parse an ISO 20022 XML message
20//!
21//! ```rust
22//! use mx20022::prelude::*;
23//! use mx20022::model::generated::pacs::pacs_008_001_13::Document;
24//!
25//! let xml = r#"<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.13"></Document>"#;
26//! let id = detect_message_type(xml).unwrap();
27//! assert_eq!(id.family, "pacs");
28//! assert_eq!(id.msg_id, "008");
29//! assert_eq!(id.version, "13");
30//! ```
31//!
32//! # Quick start: translate MT103 to pacs.008
33//!
34//! ```rust
35//! use mx20022::prelude::*;
36//!
37//! let raw = "\
38//! {1:F01BANKBEBBAXXX0000000000}\
39//! {2:I103BANKDEFFXXXXN}\
40//! {3:{108:MYREF}}\
41//! {4:\n\
42//! :20:REF123\n\
43//! :23B:CRED\n\
44//! :32A:230615EUR1000,00\n\
45//! :50K:ACME CORP\n\
46//! :59:JANE SMITH\n\
47//! :71A:SHA\n\
48//! -}\
49//! {5:{CHK:ABCDEF1234}}";
50//!
51//! let mt = mt::parse(raw).unwrap();
52//! let mt103 = mt::fields::mt103::parse_mt103(&mt.block4).unwrap();
53//! let result = mt103_to_pacs008(&mt103, "MSG-1", "2023-06-15T10:00:00").unwrap();
54//! assert!(result.warnings.is_empty() || !result.warnings.is_empty());
55//! ```
56//!
57//! # Quick start: validate a single field
58//!
59//! ```rust
60//! use mx20022::prelude::*;
61//!
62//! let registry = RuleRegistry::with_defaults();
63//! let errors = registry.validate_field(
64//!     "GB82WEST12345698765432",
65//!     "/Document/CdtTrfTxInf/CdtrAcct/Id/IBAN",
66//!     &["IBAN_CHECK"],
67//! );
68//! assert!(errors.is_empty());
69//! ```
70
71pub use mx20022_model as model;
72pub use mx20022_parse as parse;
73pub use mx20022_translate as translate;
74pub use mx20022_validate as validate;
75
76/// Curated re-exports for typical workflows.
77///
78/// Glob-import this module to get the headline error types, the
79/// translation entry-point functions, the SWIFT MT parser, and the
80/// validation registry without remembering each sub-crate's path.
81///
82/// ```
83/// use mx20022::prelude::*;
84/// ```
85pub mod prelude {
86    // ---- Errors ----
87    pub use crate::model::common::BuilderError;
88    pub use crate::parse::ParseError;
89    pub use crate::translate::mappings::{
90        TranslationError, TranslationResult, TranslationWarning, TranslationWarnings,
91    };
92    pub use crate::translate::mt::MtError;
93    pub use crate::validate::{Severity, ValidationError, ValidationResult};
94
95    // ---- Common ----
96    pub use crate::model::common::ChoiceWrapper;
97
98    // ---- Parsing / serialization ----
99    pub use crate::parse::envelope::{detect_message_type, MessageId};
100
101    // ---- Validation ----
102    pub use crate::validate::{RuleRegistry, SchemaValidator};
103
104    // ---- MT (re-export the module so users can name `mt::parse`, `mt::fields::*`) ----
105    pub use crate::translate::mt;
106
107    // ---- MT ↔ MX translation entry points ----
108    pub use crate::translate::mappings::camt053_to_mt940::camt053_to_mt940;
109    pub use crate::translate::mappings::mt103_to_pacs008::mt103_to_pacs008;
110    pub use crate::translate::mappings::mt202_to_pacs009::mt202_to_pacs009;
111    pub use crate::translate::mappings::mt940_to_camt053::mt940_to_camt053;
112    pub use crate::translate::mappings::pacs008_to_mt103::pacs008_to_mt103;
113    pub use crate::translate::mappings::pacs009_to_mt202::pacs009_to_mt202;
114}