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
sourceimpl<'de> Reader<Vec<u8>>
impl<'de> Reader<Vec<u8>>
sourcepub fn open_readfile<P: AsRef<Path>>(
database: P
) -> Result<Reader<Vec<u8>>, MaxMindDBError>
pub fn open_readfile<P: AsRef<Path>>(
database: P
) -> Result<Reader<Vec<u8>>, MaxMindDBError>
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();
sourceimpl<'de, S: AsRef<[u8]>> Reader<S>
impl<'de, S: AsRef<[u8]>> Reader<S>
sourcepub fn from_source(buf: S) -> Result<Reader<S>, MaxMindDBError>
pub fn from_source(buf: S) -> Result<Reader<S>, MaxMindDBError>
sourcepub fn lookup<T>(&'de self, address: IpAddr) -> Result<T, MaxMindDBError> where
T: Deserialize<'de>,
pub fn lookup<T>(&'de self, address: IpAddr) -> Result<T, MaxMindDBError> where
T: Deserialize<'de>,
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);
Auto Trait Implementations
impl<S> RefUnwindSafe for Reader<S> where
S: RefUnwindSafe,
impl<S> Send for Reader<S> where
S: Send,
impl<S> Sync for Reader<S> where
S: Sync,
impl<S> Unpin for Reader<S> where
S: Unpin,
impl<S> UnwindSafe for Reader<S> where
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more