address-formatter 0.1.0

Universal international address formatter
Documentation

build doc

address-formatter-rs

Universal international address formatter in Rust - data from https://github.com/OpenCageData/address-formatting

This crate is based on the amazing work of OpenCage Data who collected so many international formats of postal addresses.

The implementation is a port of the PHP, perl and js implementation of the Opencage configurations.

This is used by mimirsbrunn, a geocoder, to have nicely formatted addreses and POI.

:warning: don't forget to initialize & update the git submodules, as they held the opencage configurations.

git submodule update --init

Usage

Add address-formatter in the Cargo.toml.

use address_formatter::{Address, Component, Formatter};

let formatter = Formatter::default();

let mut addr = Address::default();
addr[Component::City] = Some("Toulouse".to_owned());
addr[Component::Country] = Some("France".to_owned());
addr[Component::CountryCode] = Some("FR".to_owned());
addr[Component::County] = Some("Toulouse".to_owned());
addr[Component::HouseNumber] = Some("17".to_owned());
addr[Component::Neighbourhood] = Some("Lafourguette".to_owned());
addr[Component::Postcode] = Some("31000".to_owned());
addr[Component::Road] = Some("Rue du Médecin-Colonel Calbairac".to_owned());
addr[Component::State] = Some("Midi-Pyrénées".to_owned());
addr[Component::Suburb] = Some("Toulouse Ouest".to_owned());

assert_eq!(
        formatter.format(addr).unwrap(),
r#"17 Rue du Médecin-Colonel Calbairac
31000 Toulouse
France
"#
        .to_owned()
)

Developing

You need an up to date rust version:

rustup update

To run the tests (especially the one based on all the opencage tests cases).

cargo test

TODO

  • There here are still some failing tests on corner cases
  • Abbreviation handling