4 releases

0.2.2 Jan 5, 2022
0.2.1 Jun 7, 2019
0.2.0 Apr 5, 2019
0.1.0 Apr 4, 2019

#10 in #address

Download history 15/week @ 2022-12-05 9/week @ 2022-12-12 17/week @ 2022-12-19 9/week @ 2022-12-26 84/week @ 2023-01-02 22/week @ 2023-01-09 29/week @ 2023-01-16 25/week @ 2023-01-23 41/week @ 2023-01-30 47/week @ 2023-02-06 41/week @ 2023-02-13 38/week @ 2023-02-20 20/week @ 2023-02-27 35/week @ 2023-03-06 71/week @ 2023-03-13 104/week @ 2023-03-20

230 downloads per month

AGPL-3.0

100KB
815 lines

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.

⚠️ 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.

#[macro_use] extern crate maplit; // just to ease the Place creation

use address_formatter::{Component, Formatter};
use Component::*;
let formatter = Formatter::default();

let data = hashmap!(
    City => "Toulouse",
    Country => "France",
    CountryCode => "FR",
    County => "Toulouse",
    HouseNumber => "17",
    Neighbourhood => "Lafourguette",
    Postcode => "31000",
    Road => "Rue du Médecin-Colonel Calbairac",
    State => "Midi-Pyrénées",
    Suburb => "Toulouse Ouest",
);

assert_eq!(
formatter.format(data).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

Dependencies

~7.5MB
~162K SLoC