Skip to main content

Crate rust_iso9362

Crate rust_iso9362 

Source
Expand description

§rust_iso9362

ISO 9362 defines the Business Identifier Code (BIC), more commonly known as the SWIFT code. Unlike ISO 3166 (a finite, enumerable list of country codes) a BIC is defined by its structure, so this crate is a parser / validator rather than a static dataset.

A BIC is 8 or 11 characters long and is composed of four parts:

PositionPartLengthCharset
1–4Business party prefix4A-Z
5–6Country code (ISO 3166-1)2A-Z
7–8Business party suffix2A-Z0-9
9–11Branch code (optional)3A-Z0-9

The business party prefix is also called the institution / bank code and the business party suffix the location code.

§Sample code

let bic = rust_iso9362::parse("DEUTDEFF500").unwrap();
assert_eq!(bic.business_party_prefix(), "DEUT");
assert_eq!(bic.country_code(), "DE");
assert_eq!(bic.business_party_suffix(), "FF");
assert_eq!(bic.branch_code(), Some("500"));
assert_eq!(bic.bic8(), "DEUTDEFF");

// 8-character BICs identify the primary office
let bic = rust_iso9362::parse("DEUTDEFF").unwrap();
assert_eq!(bic.branch_code(), None);
assert!(bic.is_primary_office());
assert_eq!(bic.bic11(), "DEUTDEFFXXX");

assert!(rust_iso9362::is_valid("DEUTDEFF"));
assert!(!rust_iso9362::is_valid("123"));

Structs§

BIC
A parsed, validated ISO 9362 Business Identifier Code.

Enums§

ParseError
The error returned when a string is not a valid ISO 9362 BIC.

Functions§

is_valid
Returns true if the given string is a syntactically valid ISO 9362 BIC.
parse
Parse and validate a BIC string, returning the structured BIC.