This page lists each globalcitizen/php-iban call and its Rust equivalent, for code moving from PHP.
The procedural PHP functions become free functions on &str. The PHP IBAN and IBANCountry classes
become the Iban and Country types. Some return types change:
- Fallible calls return
Result<_, Error>where PHP returnsfalseor"". - National checks return a
NationalCheck(Valid,Invalid,Unsupported) where PHP returnstrue,falseor"". - Country fields are typed: lengths are
u8, flags arebool, offsets areRangeInclusive<usize>, missing values areNone.
Validation and formatting
| PHP | Rust |
|---|---|
verify_iban($iban) | verify(iban), or Iban::parse(iban) to keep the value |
verify_iban($iban, true) | verify_strict(iban), or Iban::parse_strict(iban) |
iban_to_machine_format($iban) | to_machine_format(iban), or iban.machine_format() |
iban_to_human_format($iban) | to_human_format(iban), or iban.human_format() |
iban_to_obfuscated_format($iban) | to_obfuscated_format(iban), or iban.obfuscated_format() |
iban_mistranscription_suggestions($iban) | mistranscription_suggestions(iban) |
Check digits
| PHP | Rust |
|---|---|
iban_verify_checksum($iban) | verify_checksum(iban) |
iban_find_checksum($iban) | find_checksum(iban) |
iban_set_checksum($iban) | set_checksum(iban) |
iban_checksum_string_replace($s) | checksum_string_replace(s) |
iban_mod97_10($numeric) | mod97_10(numeric) |
iban_mod97_10_checksum($numeric) | mod97_10_checksum(numeric), a u8 |
iban_verify_nationalchecksum($iban) | verify_national_checksum(iban), or iban.national_check() |
iban_find_nationalchecksum($iban) | find_national_checksum(iban) |
iban_set_nationalchecksum($iban) | set_national_checksum(iban), or iban.with_national_check_digits() |
| The GMP setting | One arithmetic path handles up to 1024 ASCII digits |
Parts
| PHP | Rust |
|---|---|
iban_get_parts($iban) | parts(iban), or iban.parts() |
iban_get_country_part($iban) | iban.country_code() |
iban_get_checksum_part($iban) | iban.check_digits() |
iban_get_bban_part($iban) | iban.bban() |
iban_get_bank_part($iban) | iban.bank() |
iban_get_branch_part($iban) | iban.branch() |
iban_get_account_part($iban) | iban.account() |
iban_get_nationalchecksum_part($iban) | iban.national_check_digits() |
The iban_get_parts() keys checksum and nationalchecksum are the IbanParts fields
check_digits and national_check_digits.
Countries
IBANCountry::Name() and the other class methods map to the same Country methods as the procedural
functions below. Get a Country with country(code) or iban.country().
| PHP | Rust |
|---|---|
iban_countries() | countries(), a slice of Country. Call .code() on each. |
iban_country_get_country_name($code) | name() |
iban_country_get_domestic_example($code) | Deferred beyond v0.1.0 |
iban_country_get_bban_example($code) | Deferred beyond v0.1.0 |
iban_country_get_bban_format_swift($code) | bban_structure() |
iban_country_get_bban_format_regex($code) | bban_pattern() |
iban_country_get_bban_length($code) | bban_length() |
iban_country_get_iban_example($code) | Deferred beyond v0.1.0 |
iban_country_get_iban_format_swift($code) | iban_structure() |
iban_country_get_iban_format_regex($code) | iban_pattern() |
iban_country_get_iban_length($code) | iban_length() |
iban_country_get_bankid_start_offset($code), _stop_offset | bank_id_range() |
iban_country_get_branchid_start_offset($code), _stop_offset | branch_id_range() |
iban_country_get_nationalchecksum_start_offset($code), _stop_offset | national_check_digits_range() |
iban_country_get_registry_edition($code) | Deferred beyond v0.1.0 |
iban_country_get_country_swift_official($code) | swift_official() |
iban_country_is_sepa($code) | is_sepa() |
iban_country_get_iana($code) | Deferred beyond v0.1.0 |
iban_country_get_iso3166($code) | Deferred beyond v0.1.0 |
iban_country_get_parent_registrar($code) | Deferred beyond v0.1.0 |
iban_country_get_currency_iso4217($code) | Deferred beyond v0.1.0 |
iban_country_get_central_bank_url($code) | Deferred beyond v0.1.0 |
iban_country_get_central_bank_name($code) | Deferred beyond v0.1.0 |
iban_country_get_membership($code) | Deferred beyond v0.1.0 |
iban_country_get_is_eu_member($code) | is_eu_member() |
The IBAN class
new IBAN($iban) becomes Iban::parse(iban), which validates the input when it constructs
the value. Instance methods operate on the parsed IBAN. with_national_check_digits() returns a
Result because national repair can fail. To check a different value, call verify(other).
Laravel
To validate request input in Laravel for Rust, use IbanRule. To format IBANs in
views, use the template filters on the same page.
Behaviour that changes
The port follows the published standards where PHP's output differs from them: national check digits for Belgium, Norway, Slovakia, the Netherlands and the MOD 97-10 countries, the check digit range, strict mode and lower-case letters, short inputs, and the registry data. The README lists every difference.