Expand description
GeoIP2 and GeoLite2 database record structures
This module provides strongly-typed Rust structures that correspond to the various GeoIP2 and GeoLite2 database record formats.
§Record Types
City- Complete city-level geolocation data (most comprehensive)Country- Country-level geolocation dataEnterprise- Enterprise database with additional confidence scoresIsp- Internet Service Provider informationAnonymousIp- Anonymous proxy and VPN detectionConnectionType- Connection type classificationDomain- Domain informationAsn- Autonomous System Number dataDensityIncome- Population density and income data
§Usage Examples
use maxminddb::{Reader, geoip2};
use std::net::IpAddr;
let reader = Reader::open_readfile(
"test-data/test-data/GeoIP2-City-Test.mmdb")?;
let ip: IpAddr = "89.160.20.128".parse().unwrap();
// City lookup - nested structs are always present (default to empty)
let result = reader.lookup(ip)?;
if let Some(city) = result.decode::<geoip2::City>()? {
// Direct access to nested structs - no Option unwrapping needed
if let Some(name) = city.city.names.english {
println!("City: {}", name);
}
if let Some(code) = city.country.iso_code {
println!("Country: {}", code);
}
// Subdivisions is a Vec, empty if not present
for sub in &city.subdivisions {
if let Some(code) = sub.iso_code {
println!("Subdivision: {}", code);
}
}
}
// Country-only lookup (smaller/faster)
let result = reader.lookup(ip)?;
if let Some(country) = result.decode::<geoip2::Country>()? {
if let Some(name) = country.country.names.english {
println!("Country: {}", name);
}
}Modules§
- city
- City database model structs.
- country
- Country/City database model structs.
- enterprise
- Enterprise database model structs.
Structs§
- Anonymous
Ip - GeoIP2 Anonymous IP database record.
- Asn
- GeoLite2 ASN database record.
- City
- GeoIP2/GeoLite2 City database record.
- Connection
Type - GeoIP2 Connection-Type database record.
- Country
- GeoIP2/GeoLite2 Country database record.
- Density
Income - GeoIP2 DensityIncome database record.
- Domain
- GeoIP2 Domain database record.
- Enterprise
- GeoIP2 Enterprise database record.
- Isp
- GeoIP2 ISP database record.
- Names
- Localized names for geographic entities.