BaseIban

Struct BaseIban 

Source
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 Clone for BaseIban

Source§

fn clone(&self) -> BaseIban

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BaseIban

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for BaseIban

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Iban> for BaseIban

Source§

fn from(value: Iban) -> BaseIban

Converts to this type from the input type.
Source§

impl FromStr for BaseIban

Source§

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

The associated error which can be returned from parsing.
Source§

impl Hash for BaseIban

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IbanLike for BaseIban

Source§

fn electronic_str(&self) -> &str

Get the IBAN in the electronic format, without whitespace. This method is simply a view into the inner string. Read more
Source§

fn country_code(&self) -> &str

Get the country code of the IBAN. This method simply returns a slice of the inner representation. Read more
Source§

fn check_digits_str(&self) -> &str

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
Source§

fn check_digits(&self) -> u8

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
Source§

fn bban_unchecked(&self) -> &str

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
Source§

impl PartialEq for BaseIban

Source§

fn eq(&self, other: &BaseIban) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> TryFrom<&'a str> for BaseIban

Source§

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

The type returned in the event of a conversion error.
Source§

impl TryFrom<BaseIban> for Iban

Source§

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.

Source§

type Error = ParseIbanError

The type returned in the event of a conversion error.
Source§

impl Copy for BaseIban

Source§

impl Eq for BaseIban

Source§

impl StructuralPartialEq for BaseIban

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.