pub struct BaseIban { /* private fields */ }Expand description
Represents an IBAN that passed basic checks, but not necessarily the BBAN validation. This corresponds to the validation as described in ISO 13616-1.
To be exact, the IBAN…
- must start with two uppercase ASCII letters, followed by two digits, followed by any number of digits and ASCII letters.
- must have a valid checksum.
- must contain no whitespace, or be in the paper format, where characters are in space-separated groups of four.
Note that most useful methods are supplied by the trait IbanLike. The Display trait provides pretty
print formatting.
A BaseIban does not enforce the country specific BBAN format as
described in the Swift registry. In most cases, you probably want to use
an Iban instead, which additionally does country specific validation.
When parsing an Iban fails, the ParseIbanError will contain the
BaseIban if it was valid.
§Examples
An example of parsing and using a correct IBAN:
use iban::{BaseIban, IbanLike};
let iban: BaseIban = "MR13 0002 0001 0100 0012 3456 753".parse()?;
assert_eq!(iban.electronic_str(), "MR1300020001010000123456753");
// The pretty print 'paper' format
assert_eq!(iban.to_string(), "MR13 0002 0001 0100 0012 3456 753");
assert_eq!(iban.country_code(), "MR");
assert_eq!(iban.check_digits_str(), "13");
assert_eq!(iban.check_digits(), 13);
assert_eq!(iban.bban_unchecked(), "00020001010000123456753");An example of parsing invalid IBANs:
use iban::{BaseIban, ParseBaseIbanError};
assert_eq!(
"MR$$".parse::<BaseIban>(),
Err(ParseBaseIbanError::InvalidFormat)
);
assert_eq!(
"MR0000020001010000123456754".parse::<BaseIban>(),
Err(ParseBaseIbanError::InvalidChecksum)
);§Formatting
The IBAN specification describes two formats: an electronic format without
whitespace and a paper format which seperates the IBAN in groups of
four characters. Both will be parsed correctly by this crate. When
formatting, Debug can be used to output the former and Display for
the latter. This is true for a BaseIban as well as an Iban.
Alternatively, you can use IbanLike::electronic_str to obtain the
electronic format as a string slice.
let iban: iban::BaseIban = "RO66BACX0000001234567890".parse()?;
// Use Debug for the electronic format.
assert_eq!(&format!("{:?}", iban), "RO66BACX0000001234567890");
// Use Display for the paper format.
assert_eq!(&format!("{}", iban), "RO66 BACX 0000 0012 3456 7890");Trait Implementations§
Source§impl FromStr for BaseIban
impl FromStr for BaseIban
Source§fn from_str(address: &str) -> Result<Self, Self::Err>
fn from_str(address: &str) -> Result<Self, Self::Err>
Parse a basic iban without taking the BBAN into consideration.
§Errors
If the string does not match the IBAN format or the checksum is
invalid, an ParseBaseIbanError will be
returned.
Source§type Err = ParseBaseIbanError
type Err = ParseBaseIbanError
Source§impl IbanLike for BaseIban
impl IbanLike for BaseIban
Source§fn electronic_str(&self) -> &str
fn electronic_str(&self) -> &str
Source§fn country_code(&self) -> &str
fn country_code(&self) -> &str
Source§fn check_digits_str(&self) -> &str
fn check_digits_str(&self) -> &str
check_digits. Read moreSource§fn check_digits(&self) -> u8
fn check_digits(&self) -> u8
check_digits_str. Read moreSource§fn bban_unchecked(&self) -> &str
fn bban_unchecked(&self) -> &str
&str. Note that the BBAN is not
necessarily valid if this is not guaranteed by the implementing type.
Use Iban::bban to guarantee a correct BBAN. Read moreSource§impl<'a> TryFrom<&'a str> for BaseIban
impl<'a> TryFrom<&'a str> for BaseIban
Source§fn try_from(value: &'a str) -> Result<Self, Self::Error>
fn try_from(value: &'a str) -> Result<Self, Self::Error>
Parse a basic IBAN without taking the BBAN into consideration.
§Errors
If the string does not match the IBAN format or the checksum is
invalid, an ParseBaseIbanError will be
returned.
Source§type Error = ParseBaseIbanError
type Error = ParseBaseIbanError
Source§impl TryFrom<BaseIban> for Iban
impl TryFrom<BaseIban> for Iban
Source§fn try_from(base_iban: BaseIban) -> Result<Iban, ParseIbanError>
fn try_from(base_iban: BaseIban) -> Result<Iban, ParseIbanError>
Parse an IBAN without taking the BBAN into consideration.
§Errors
If the string does not match the IBAN format or the checksum is
invalid, ParseIbanError::InvalidBaseIban will be
returned. If the country format is invalid or unknown, the other
variants will be returned with the BaseIban giving
access to some basic functionality nonetheless.