Iban

Struct Iban 

Source
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

Source

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");
Source

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"));
Source

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 Clone for Iban

Source§

fn clone(&self) -> Iban

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 Iban

Source§

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

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

impl Display for Iban

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 Iban

Source§

type Err = ParseIbanError

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

fn from_str(address: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Iban

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 Iban

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 Iban

Source§

fn eq(&self, other: &Iban) -> 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 Iban

Source§

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

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 Iban

Source§

impl Eq for Iban

Source§

impl StructuralPartialEq for Iban

Auto Trait Implementations§

§

impl Freeze for Iban

§

impl RefUnwindSafe for Iban

§

impl Send for Iban

§

impl Sync for Iban

§

impl Unpin for Iban

§

impl UnwindSafe for Iban

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.