Enum ip2location::DB
source · pub enum DB {
LocationDb(LocationDB),
ProxyDb(ProxyDB),
}Variants§
LocationDb(LocationDB)
ProxyDb(ProxyDB)
Implementations§
source§impl DB
impl DB
sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<DB, Error>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<DB, Error>
Consume the unopened db and open the file. Loads a Ip2Location/Ip2Proxy Database .bin file from path
Example usage
use ip2location::LocationDB;
let mut db = LocationDB::from_file("data/IP2LOCATION-LITE-DB1.BIN").unwrap();sourcepub fn from_file_mmap<P: AsRef<Path>>(path: P) -> Result<DB, Error>
pub fn from_file_mmap<P: AsRef<Path>>(path: P) -> Result<DB, Error>
Consume the unopened db and mmap the file. Loads a Ip2Location/Ip2Proxy Database .bin file from path using mmap (memap) feature.
Example usage
use ip2location::DB;
let mut db = DB::from_file_mmap("data/IP2PROXY-IP-COUNTRY.BIN").unwrap();sourcepub fn print_db_info(&self)
pub fn print_db_info(&self)
Prints the DB Information of Ip2Location/Ip2Proxy to console
Example usage
use ip2location::DB;
let mut db = DB::from_file_mmap("data/IP2LOCATION-LITE-DB1.BIN").unwrap();
db.print_db_info();sourcepub fn ip_lookup(&mut self, ip: IpAddr) -> Result<Record, Error>
pub fn ip_lookup(&mut self, ip: IpAddr) -> Result<Record, Error>
Lookup for the given IPv4 or IPv6 and returns the Geo information or Proxy 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")