Struct ip2proxy::Database

source ·
pub struct Database { /* private fields */ }
Expand description

An IP2Proxy BIN database.

Implementations§

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.

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.

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);

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");

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));

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

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

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

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

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§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.