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<ReaderMaxMindDBError>

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: SocketAddr) -> Result<T, MaxMindDBError>

Lookup the socket address in the opened MaxMind DB

Example:

use maxminddb::geoip2;
use std::net::SocketAddr;
use std::str::FromStr;

let reader = maxminddb::Reader::open("test-data/test-data/GeoIP2-City-Test.mmdb").unwrap();

let ip: SocketAddr = FromStr::from_str("89.160.20.128:0").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.