Expand description
§MaxMind DB Reader
This library reads the MaxMind DB format, including the GeoIP2 and GeoLite2 databases.
§Features
This crate provides several optional features for performance and functionality:
mmap
(default: disabled): Enable memory-mapped file access for better performance in long-running applicationssimdutf8
(default: disabled): Use SIMD instructions for faster UTF-8 validation during string decodingunsafe-str-decode
(default: disabled): Skip UTF-8 validation entirely for maximum performance (~20% faster lookups)
Note: simdutf8
and unsafe-str-decode
are mutually exclusive.
§Database Compatibility
This library supports all MaxMind DB format databases:
- GeoIP2 databases (City, Country, Enterprise, ISP, etc.)
- GeoLite2 databases (free versions)
- Custom MaxMind DB format databases
§Thread Safety
The Reader
is Send
and Sync
, making it safe to share across threads.
This makes it ideal for web servers and other concurrent applications.
§Quick Start
use maxminddb::{Reader, geoip2};
use std::net::IpAddr;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open database file
let reader = Reader::open_readfile("/path/to/GeoIP2-City.mmdb")?;
// Look up an IP address
let ip: IpAddr = "89.160.20.128".parse()?;
if let Some(city) = reader.lookup::<geoip2::City>(ip)? {
if let Some(country) = city.country {
println!("Country: {}", country.iso_code.unwrap_or("Unknown"));
}
}
Ok(())
}
Modules§
- geoip2
- GeoIP2 and GeoLite2 database record structures
Structs§
- Metadata
- Reader
- A reader for the MaxMind DB format. The lifetime
'data
is tied to the lifetime of the underlying buffer holding the contents of the database file. - Within
- Within
Item