Crate mt940

Source
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§

AvailableBalance
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.
MT940Parser
A pest parser for parsing a MT940 structure and fields.
Message
A single, parsed MT940 message.
RequiredTagNotFoundError
Error thrown if a required tag was not found.
StatementLine
A StatementLine holds information contained in tag :61: and tag :86:.
UnexpectedTagError
Error thrown when an unexpected tag was found.
VariantNotFound
Error thrown if a variant for an enum can’t be found.

Enums§

DateParseError
DebitOrCredit
Indiciates whether a transaction was Debit or Credit.
ExtDebitOrCredit
Like DebitOrCredit with additional reverse variants.
ParseError
Error thrown when parsing fails.
Rule
TransactionTypeIdentificationCode
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.