Zipcodes
Zipcodes is a simple library for querying U.S. zipcodes. It pre-loads all zipcode data into memory at compile time, making it fast and efficient.
⚠️ The zipcode data was last updated on: Feb. 16, 2025 ⚠️
The minimum supported Rust version (MSRV) is 1.82.
Installation
Add zipcodes to your project's dependencies:
$ cargo add zipcodes
Or, add the following line to your Cargo.toml:
[]
= "0.3.0"
Quick Start
This example demonstrates the primary matching function and shows the full data structure for a located zipcode.
use zipcodes;
Example Output
Zipcode {
acceptable_cities: [],
active: true,
area_codes: [
"281",
"832",
],
city: "Cypress",
country: "US",
lat: "29.9857",
long: "-95.6548",
state: "TX",
timezone: "America/Chicago",
unacceptable_cities: [],
world_region: "NA",
zip_code: "77429",
zip_code_type: "STANDARD",
}
Examples
All fallible functions in this library return a zipcodes::Result<T>. The ? operator is used for brevity in these examples.
Validating a Zipcode
Use is_real() for a simple boolean check on a zipcode's existence.
use is_real;
Advanced Filtering
The filter_by() function allows for powerful, custom queries using a vector of closures. This lets you find all zipcodes that match multiple specific criteria.
use ;
Listing All Zipcodes
You can get a complete list of all zipcodes in the database.
use list_all;
let all_zips = list_all;
println!;
Zipcode Data
The zipcode data is embedded directly into the library at compile time via a build.rs script. This ensures fast lookups at runtime without needing to read from a file or an external database.
Contributing
Have an idea for a new feature? Feel free to open a pull request and contribute!