Database

Struct Database 

Source
pub struct Database { /* private fields */ }
Expand description

An IP2Proxy BIN database.

Implementations§

Source§

impl Database

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open a database file.

§Example
use ip2proxy::Database;

let db = Database::open("data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN")?;
§Errors
  • Error while opening the file.
  • Error while reading from the file.
  • Invalid data in header section or index section.
Source

pub fn query(&self, addr: IpAddr, query: Columns) -> Result<Option<Row>>

Look up information for an IP address.

The Columns parameter allows optimizing the lookup by limiting the number columns to retrieve.

Returns a Row, if any.

§Example
use ip2proxy::{Columns, Database, Row};

let db = Database::open("data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN")?;

let row = db.query("1.0.0.1".parse()?, Columns::all())?;
assert_eq!(row.and_then(|r| r.is_proxy()), Some(true));
§Errors
  • Error while reading from the source.
  • Invalid row or string data.
Source

pub fn package_version(&self) -> u8

Get package version.

§Example
use ip2proxy::Database;

let db = Database::open("data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN")?;
assert_eq!(db.package_version(), 4);
Source

pub fn database_version(&self) -> String

Get database version as YY.M.D.

§Example
use ip2proxy::Database;

let db = Database::open("data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN")?;
assert_eq!(db.database_version(), "16.11.17");
Source

pub fn columns(&self) -> Columns

Get the set of supported columns.

§Example
use ip2proxy::{Columns, Database};

let db = Database::open("data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN")?;
assert!(db.columns().contains(Columns::PROXY_TYPE));
Source

pub fn year(&self) -> u8

Get the database creation year. Convention is 16 for 2016.

Source

pub fn month(&self) -> u8

Get the database creation month. Convention is 1 for January.

Source

pub fn day(&self) -> u8

Get the database creation day. Convention is 1 for the first day of the month.

Source

pub fn rows_ipv4(&self) -> u32

Get the number of rows for IPv4 addresses. Rows can cover a range, so there may be information for many more IP addresses.

Source

pub fn rows_ipv6(&self) -> u32

Get the number of rows for IPv6 addresses. Rows can cover a range, so there may be information for many more IP addresses.

Trait Implementations§

Source§

impl Debug for Database

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.