rust_iso/iso9362
A rust crate providing ISO 9362 (Business Identifier Code / BIC, a.k.a. SWIFT code) parsing and validation.
What is ISO 9362
ISO 9362 is an international standard for Business Identifier Codes (BIC), a standard published by the International Organization for Standardization (ISO) as a way to uniquely identify banks and financial institutions worldwide. The BIC is also known as the SWIFT code, SWIFT-BIC, or SWIFT address.
A BIC is 8 or 11 characters long and is made up of:
- Business party prefix – four alphabetic characters identifying the business party (institution / bank code).
- Country code – two alphabetic characters, the ISO 3166-1 alpha-2 code of the country in which the business party is located.
- Business party suffix – two alphanumeric characters (the location code).
- Branch code – an optional three alphanumeric characters identifying a specific branch;
XXX, or its absence, denotes the primary office.-- Wikipedia
Unlike ISO 3166, ISO 9362 does not define a fixed, enumerable dataset (the full registry of assigned BICs is maintained by SWIFT), so this crate is a parser / validator that decomposes a BIC into its component parts.
| Position | Part | Length | Charset |
|---|---|---|---|
| 1–4 | Business party prefix | 4 | A-Z |
| 5–6 | Country code (ISO 3166-1) | 2 | A-Z |
| 7–8 | Business party suffix | 2 | A-Z0-9 |
| 9–11 | Branch code (optional) | 3 | A-Z0-9 |
Installing
[]
= "0.1.0"
Features
-
serde— implementsSerialize/DeserializeforBIC. ABICserialises to its canonical code string and deserialises case-insensitively viaBIC::parse. Enable with:= { = "0.1.0", = ["serde"] } -
iso3166— addsBIC::country(), which resolves the embedded ISO 3166-1 country code to arust_iso3166::CountryCodeusing therust_iso3166crate. -
cli— builds theiso9362command-line lookup tool (pulls inprettytable-rs). Off by default; install withcargo install rust_iso9362 --features cli.
The minimum supported Rust version is 1.85.
Using
// Parse + validate (returns Option)
let bic = parse.unwrap;
// Or get a Result with a descriptive error
let bic = BICparse.unwrap;
assert_eq!; // a.k.a. bank_code()
assert_eq!;
assert_eq!; // a.k.a. location_code()
assert_eq!;
assert_eq!;
assert_eq!;
assert!;
// 8-character BICs identify the primary office
let bic = BICparse.unwrap;
assert_eq!;
assert!;
assert_eq!;
// Cheap validity check
assert!;
assert!;
// FromStr is implemented too
let bic: BIC = "DEUTDEFF".parse.unwrap;
// With the `iso3166` feature:
// let country = bic.country().unwrap();
// assert_eq!(country.alpha3, "DEU");
Data sample:
BIC
Contributing
Feel free to submit a pull request or create an issue. or request to rust-iso
License
rust-iso/rust_iso9362 is licensed under the Apache-2.0 license.