Skip to main content

DB

Enum DB 

Source
pub enum DB {
    LocationDb(LocationDB),
    ProxyDb(ProxyDB),
}
Expand description

A loaded IP2Location or IP2Proxy database.

Created via DB::from_file. The underlying BIN file is memory-mapped and remains mapped for the lifetime of this value.

Variants§

§

LocationDb(LocationDB)

An IP2Location geolocation database.

§

ProxyDb(ProxyDB)

An IP2Proxy proxy-detection database.

Implementations§

Source§

impl DB

Source

pub fn from_file<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("data/IP2PROXY-IP-COUNTRY.BIN").unwrap();
Source

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("data/IP2LOCATION-LITE-DB1.BIN").unwrap();
db.print_db_info();
Source

pub fn ip_lookup(&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")

Trait Implementations§

Source§

impl Debug for DB

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for DB

§

impl RefUnwindSafe for DB

§

impl Send for DB

§

impl Sync for DB

§

impl Unpin for DB

§

impl UnwindSafe for DB

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.