Crate libpostal_rust
source · [−]Expand description
libpostal-rust: A high-level, threadsafe wrapper around libpostal
The open source C library
libpostal provides support for
parsing and normalizing addresses using an external language model trained
on addresses around the world. We provide a high-level Rust wrapper around
that library, in a way that it can be linked into your main Rust binary.
Note that you will need to use libpostal_data (included with libpostal)
to download and install about 2GB of language model data:
sudo libpostal_data download all /usr/local/share/libpostalOnce this is done, you can parse addresses as follows:
use libpostal_rust::{ParseAddressOptions, parse_address};
let addr = "781 Franklin Ave Crown Heights Brooklyn NYC NY 11216 USA";
let opt = ParseAddressOptions::default();
let parsed = parse_address(addr, &opt).unwrap();
assert_eq!(parsed.get("state"), Some(&"ny".to_owned()));You can turn parsed back into a nicely-formatted address (almost anywhere
in the world) by using
address-formatter’s support
for OpenCage address templates.
Structs
Options for use with expand_address.
Options for use with parse_address.
Enums
A libpostal-related error.
Functions
Try to expand any abbreviations in an address.
Parse an address into its component values.
Type Definitions
A Result type which defaults to libpostal_rust::Error.