Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
geodb-rs
A high-performance, pure-Rust geographic database with countries, states/regions, cities, aliases, phone codes, currencies, timezones, and WebAssembly support.
This repository is a Cargo workspace containing:
geodb-coreβ main geographic database library (published on crates.io)geodb-wasmβ WebAssembly bindings + browser demo (Trunk-based)geodb-cliβ optional CLI (future)
Overview
geodb-core provides:
- π Fast loading from compressed JSON or binary cache
- πΎ Automatic caching based on dataset file and filters
- π Flexible lookups: ISO codes, names, aliases, phone codes
- π Countries, states/regions, cities, populations
- πΊ Accurate metadata: region, subregion, currency
- π Phone code search
- β± Zero-copy internal model
- π¦ Pure Rust β no unsafe
- πΈ WASM support via
geodb-wasm
The dataset is adapted from
https://github.com/dr5hn/countries-states-cities-database
(licensed under CC-BY-4.0, attribution required).
Important: Data source we rely on
geodb-core ships and expects the upstream dataset from the following file in the dr5hn/countries-states-cities-database repository:
The default loader uses a copy of this file placed under
crates/geodb-core/data/countries+states+cities.json.gzand builds a binary cache alongside it. If you update or replace the dataset, ensure it retains the same JSON structure. Please observe the CCβBYβ4.0 license and attribution of the upstream project.
Installation
For Rust applications
[]
= "0.2"
For WebAssembly (browser/Node)
[]
= "0.2"
Quick Start
use *;
Loading & Caching
Default loading
Loads from:
geodb-core/data/countries+states+cities.json.gz
Creates automatic cache:
countries+states+cities.json.ALL.bin
let db = load?;
Load from a custom file
let db = load_from_path?;
Cache becomes:
worlddata.json.ALL.bin
Filtered loading (ISO2)
let db = load_filtered_by_iso2?;
Cache:
countries+states+cities.json.DE_US.bin
Cache rules:
<dataset_filename>.<filter>.bin
Usage Examples
List all countries
use *;
let db = load?;
for country in db.countries
Find by ISO code
if let Some = db.find_country_by_iso2
Country details
if let Some = db.find_country_by_iso2
States & cities
if let Some = db.find_country_by_iso2
Phone search
let countries = db.find_countries_by_phone_code;
Search for cities named βSpringfieldβ
let results: = db.countries
.iter
.flat_map
.collect;
WebAssembly (geodb-wasm)
Exports:
search_country_prefixsearch_countries_by_phonesearch_state_substringsearch_city_substringsmart_searchget_stats
To run locally:
Live demo:
https://trahe.eu/geodb-rs.html
Workspace Layout
geodb-rs/
βββ crates/
β βββ geodb-core
β βββ geodb-wasm
β βββ geodb-cli (planned)
βββ data/
β βββ countries+states+cities.json.gz
β βββ geodb.standard.bin
βββ examples/
βββ scripts/
βββ README.md
Performance
- Initial load from JSON: ~20β40ms
- Cached load: ~1β3ms
- Memory use: 10β15MB
- Fully zero-copy internal model
Contributing
Before submitting PRs:
cargo fmt
cargo clippy --all-targets -- -D warnings
cargo test --workspace
cargo doc --workspace
cargo sort -cwg
taplo format --check
cargo deny check
License
Code
MIT License.
Data Attribution (Required)
This project includes data from:
countries-states-cities-database
https://github.com/dr5hn/countries-states-cities-database
Licensed under Creative Commons Attribution 4.0 (CC-BY-4.0).
Attribution is required if you redistribute or use the dataset.
Links
- Repo: https://github.com/holg/geodb-rs
- Docs: https://docs.rs/geodb-core
- Crate: https://crates.io/crates/geodb-core
Made with β€οΈ in Rust.