Struct maxminddb::Reader
[−]
[src]
pub struct Reader { pub metadata: Metadata, // some fields omitted }
A reader for the MaxMind DB format
Fields
metadata: Metadata
Methods
impl Reader
[src]
fn open(database: &str) -> Result<Reader, MaxMindDBError>
Open a MaxMind DB database file.
Example
let reader = maxminddb::Reader::open("test-data/test-data/GeoIP2-City-Test.mmdb").unwrap();
fn lookup<T: Decodable>(&self, address: IpAddr) -> Result<T, MaxMindDBError>
Lookup the socket address in the opened MaxMind DB
Example:
use maxminddb::geoip2; use std::net::IpAddr; use std::str::FromStr; let reader = maxminddb::Reader::open("test-data/test-data/GeoIP2-City-Test.mmdb").unwrap(); let ip: IpAddr = FromStr::from_str("89.160.20.128").unwrap(); let city: geoip2::City = reader.lookup(ip).unwrap(); print!("{:?}", city);
Note that SocketAddr requires a port, which is not needed to look up the address in the database. This library will likely switch to IpAddr if the feature gate for that is removed.