pub struct Iban { /* private fields */ }Expand description
Represents an IBAN. To obtain it, make use of the parse() function, which will make sure the
string follows the ISO 13616 standard. Apart from its own methods, Iban implements IbanLike,
which provides more functionality.
The impementation of Display provides spaced formatting of the IBAN. Electronic
formatting can be obtained via electronic_str.
A valid 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.
- must adhere to the country-specific format.
Sometimes it may be desirable to accept IBANs that do not have their
country registered in the IBAN registry, or it may simply be unimportant
whether the country’s BBAN format was followed. In that case, you can use
a BaseIban instead.
§Examples
use iban::*;
let address = "KZ86125KZT5004100100".parse::<iban::Iban>()?;
assert_eq!(address.to_string(), "KZ86 125K ZT50 0410 0100");§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::Iban = "RO66BACX0000001234567890".parse()?;
// Use Debug for the electronic format.
assert_eq!(&format!("{:?}", iban), "RO66BACX0000001234567890");
// Use Display for the pretty print format.
assert_eq!(&format!("{}", iban), "RO66 BACX 0000 0012 3456 7890");Implementations§
Source§impl Iban
impl Iban
Sourcepub fn bban(&self) -> &str
pub fn bban(&self) -> &str
Get the BBAN part of the IBAN, as a &str. This method, in contrast to IbanLike::bban_unchecked,
is only available on the Iban structure, which means the returned BBAN string is always correct.
§Example
use iban::*;
let iban: Iban = "DE44 5001 0517 5407 3249 31".parse()?;
assert_eq!(iban.bban(), "500105175407324931");Sourcepub fn bank_identifier(&self) -> Option<&str>
pub fn bank_identifier(&self) -> Option<&str>
Get the bank identifier of the IBAN. The bank identifier might not be
defined, in which case this method returns None.
§Example
use iban::*;
let iban: Iban = "AD12 0001 2030 2003 5910 0100".parse()?;
assert_eq!(iban.bank_identifier(), Some("0001"));Sourcepub fn branch_identifier(&self) -> Option<&str>
pub fn branch_identifier(&self) -> Option<&str>
Get the branch identifier of the IBAN. The branch identifier might not be
defined, in which case this method returns None.
§Example
use iban::*;
let iban: Iban = "AD12 0001 2030 2003 5910 0100".parse()?;
assert_eq!(iban.branch_identifier(), Some("2030"));Trait Implementations§
Source§impl IbanLike for Iban
impl IbanLike for Iban
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 Iban
impl<'a> TryFrom<&'a str> for Iban
Source§fn try_from(value: &'a str) -> Result<Self, Self::Error>
fn try_from(value: &'a str) -> Result<Self, Self::Error>
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.
Source§type Error = ParseIbanError
type Error = ParseIbanError
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.