Crates.io | address-formatter |
lib.rs | address-formatter |
version | 0.2.2 |
source | src |
created_at | 2019-04-04 15:24:46.897618 |
updated_at | 2022-01-05 08:33:26.108291 |
description | Universal international address formatter |
homepage | |
repository | https://github.com/CanalTP/address-formatter-rs |
max_upload_size | |
id | 125836 |
size | 342,604 |
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
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()
)
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