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/libpostal
Once 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§
- Expand
Address Options - Options for use with
expand_address
. - Parse
Address Options - Options for use with
parse_address
.
Enums§
- Error
- A
libpostal
-related error.
Functions§
- expand_
address - Try to expand any abbreviations in an address.
- parse_
address - Parse an address into its component values.
Type Aliases§
- Result
- A
Result
type which defaults tolibpostal_rust::Error
.