Struct ip2proxy::Database [−][src]
pub struct Database { /* fields omitted */ }
Expand description
An IP2Proxy BIN database.
Implementations
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 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.