pub struct Reader<S: AsRef<[u8]>> {
    pub metadata: Metadata,
    /* private fields */
}
Expand description

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.

Fields

metadata: Metadata

Implementations

Open a MaxMind DB database file by loading it into memory.

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

Open a MaxMind DB database from anything that implements AsRef<u8>

Example
use std::fs;
let buf = fs::read("test-data/test-data/GeoIP2-City-Test.mmdb").unwrap();
let reader = maxminddb::Reader::from_source(buf).unwrap();

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_readfile("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);

Iterate over blocks of IP networks in the opened MaxMind DB

Example:

use ipnetwork::IpNetwork;
use maxminddb::{geoip2, Within};

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

let ip_net = IpNetwork::V6("::/0".parse().unwrap());
let mut iter: Within<geoip2::City, _> = reader.within(ip_net).unwrap();
while let Some(next) = iter.next() {
    let item = next.unwrap();
    println!("ip_net={}, city={:?}", item.ip_net, item.info);
}

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.