pub struct LocationDB { /* private fields */ }Expand description
An opened IP2Location geolocation BIN database.
Holds the parsed header metadata and a memory-mapped [Source].
Use DB::from_file to open, or
LocationDB::from_file to open directly.
Implementations§
Source§impl LocationDB
impl LocationDB
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error>
Loads a Ip2Location Database .bin file from path using mmap (memap) feature.
§Example usage
use ip2location::DB;
let mut db = DB::from_file("data/IP2LOCATION-LITE-DB1.BIN").unwrap();Sourcepub fn print_db_info(&self)
pub fn print_db_info(&self)
Prints the DB Information to console
§Example usage
use ip2location::DB;
let mut db = DB::from_file("data/IP2LOCATION-LITE-DB1.BIN").unwrap();
db.print_db_info();Sourcepub fn ip_lookup(&self, ip: IpAddr) -> Result<LocationRecord<'_>, Error>
pub fn ip_lookup(&self, ip: IpAddr) -> Result<LocationRecord<'_>, Error>
Lookup for the given IPv4 or IPv6 and returns the Geo information
§Example usage
use ip2location::{DB, Record};
let mut db = DB::from_file("data/IP2LOCATION-LITE-DB1.IPV6.BIN").unwrap();
let geo_info = db.ip_lookup("2a01:cb08:8d14::".parse().unwrap()).unwrap();
println!("{:#?}", geo_info);
let record = if let Record::LocationDb(rec) = geo_info {
Some(rec)
} else { None };
let geo_info = record.unwrap();
assert!(!geo_info.country.is_none());
assert_eq!(geo_info.country.unwrap().short_name, "FR")Trait Implementations§
Auto Trait Implementations§
impl Freeze for LocationDB
impl RefUnwindSafe for LocationDB
impl Send for LocationDB
impl Sync for LocationDB
impl Unpin for LocationDB
impl UnwindSafe for LocationDB
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more