Struct ip2location::ProxyDB
source · pub struct ProxyDB { /* private fields */ }Implementations§
source§impl ProxyDB
impl ProxyDB
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 Ip2Proxy Database .bin file from path using mmap (memap) feature.
Example usage
use ip2location::DB;
let mut db = DB::from_file("data/IP2PROXY-IP-COUNTRY.BIN").unwrap();sourcepub fn ip_lookup(&mut self, ip: IpAddr) -> Result<ProxyRecord<'_>, Error>
pub fn ip_lookup(&mut self, ip: IpAddr) -> Result<ProxyRecord<'_>, Error>
Lookup for the given IPv4 or IPv6 and returns the Proxy information
Example usage
use ip2location::{DB, Record};
let mut db = DB::from_file("data/IP2PROXY-IP-COUNTRY.BIN").unwrap();
let geo_info = db.ip_lookup("1.1.1.1".parse().unwrap()).unwrap();
println!("{:#?}", geo_info);
let record = if let Record::ProxyDb(rec) = geo_info {
Some(rec)
} else { None };
let geo_info = record.unwrap();
assert!(!geo_info.country.is_none());pub fn print_db_info(&self)
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for ProxyDB
impl Send for ProxyDB
impl Sync for ProxyDB
impl Unpin for ProxyDB
impl UnwindSafe for ProxyDB
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