Expand description
A fast and strict MT940 parser.
§Examples
use mt940::parse_mt940;
let input = "\
:20:3996-11-11111111\r\n\
:25:DABADKKK/111111-11111111\r\n\
:28C:00001/001\r\n\
:60F:C090924EUR54484,04\r\n\
:61:0909250925DR583,92NMSC1110030403010139//1234\r\n\
:86:11100304030101391234\r\n\
Beneficiary name\r\n\
Something else\r\n\
:61:0910010930DR62,60NCHGcustomer id//bank id\r\n\
:86:Fees according to advice\r\n\
:62F:C090930EUR53126,94\r\n\
:64:C090930EUR53189,31\r\n\
\r\n";
let input_parsed = parse_mt940(input).unwrap();
assert_eq!(input_parsed[0].transaction_ref_no, "3996-11-11111111");
§Sanitizing input
In case your input is non-standard conformant, it will be refused. This is the case, for instance, if it contains invalid characters which are not specified in the SWIFT MT101 character set. Since this is the case quite often with international banks, you can use the provided sanitizer to try to sanitize your input and make it MT940-compliant before trying to parse it:
use mt940::parse_mt940;
use mt940::sanitizers::to_swift_charset;
let input = "\
:20:äö===hallo===\r\n\
:25:DABADKKK/111111-11111111\r\n\
:28C:00001/001\r\n\
:60F:C090924EUR54484,04\r\n\
:61:0909250925DR583,92NMSC1110030403010139//1234\r\n\
:86:ääääää«»«»«ëáßðæ©®bñéë«óüë«ó»µ©b©äé\r\n\
:61:0910010930DR62,60NCHGcustomer id//bank id\r\n\
:86:ääääää䤤¤¤¤¤¤¤¤€€€€€€€€€€€€€€€³¹²³\r\n\
:62F:C090930EUR53126,94\r\n\
:64:C090930EUR53189,31\r\n\
\r\n";
let sanitized_input = to_swift_charset(input);
let input_parsed = parse_mt940(&sanitized_input).unwrap();
assert_eq!(input_parsed[0].transaction_ref_no, "ao...hallo...");
Modules§
- sanitizers
- This module contains a collection of sanitizers which is really just a fancy way of saying that this is a bunch of functions which take strings, change them, and give them back.
Structs§
- Available
Balance - Represents the currently available balance of an account.
- Balance
- Represents a balance of an account in between statements or at the start of a statement.
- Field
- This is a generic struct that serves as a container for the first pass of the parser.
- MT940
Parser - A pest parser for parsing a MT940 structure and fields.
- Message
- A single, parsed MT940 message.
- Required
TagNot Found Error - Error thrown if a required tag was not found.
- Statement
Line - A
StatementLine
holds information contained in tag:61:
and tag:86:
. - Unexpected
TagError - Error thrown when an unexpected tag was found.
- Variant
NotFound - Error thrown if a variant for an enum can’t be found.
Enums§
- Date
Parse Error - Debit
OrCredit - Indiciates whether a transaction was
Debit
orCredit
. - ExtDebit
OrCredit - Like
DebitOrCredit
with additional reverse variants. - Parse
Error - Error thrown when parsing fails.
- Rule
- Transaction
Type Identification Code - Enum containing every SEPA-specified transaction type identification code.
Functions§
- parse_
fields - Parse a MT940 statement to a list of its fields.
- parse_
mt940 - Parse and validate a MT940 statement.