Struct iban::BaseIban [−][src]
pub struct BaseIban { /* fields omitted */ }
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. Additionally its checksum should be valid. It should either 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.
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 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)
);
Trait Implementations
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.
type Err = ParseBaseIbanError
type Err = ParseBaseIbanError
The associated error which can be returned from parsing.
Get the IBAN in the electronic format, without whitespace. This method is simply a view into the inner string. Read more
Get the country code of the IBAN. This method simply returns a slice of the inner representation. Read more
Get the check digits of the IBAN, as a string slice. This method simply returns
a slice of the inner representation. To obtain an integer instead,
use check_digits
. Read more
Get the check digits of the IBAN. This method parses the digits to an
integer, performing slightly more work than check_digits_str
. Read more
Get the BBAN part of the IBAN, as a &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 more
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.
type Error = ParseBaseIbanError
type Error = ParseBaseIbanError
The type returned in the event of a conversion 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.
type Error = ParseIbanError
type Error = ParseIbanError
The type returned in the event of a conversion error.
Auto Trait Implementations
impl RefUnwindSafe for BaseIban
impl UnwindSafe for BaseIban
Blanket Implementations
Mutably borrows from an owned value. Read more