pub struct Database { /* private fields */ }
Expand description
An IP2Proxy BIN database.
Implementations§
source§impl Database
impl Database
sourcepub fn query(&self, addr: IpAddr, query: Columns) -> Result<Option<Row>>
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.
sourcepub fn package_version(&self) -> u8
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);
sourcepub fn database_version(&self) -> String
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");
sourcepub fn columns(&self) -> Columns
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));
sourcepub fn day(&self) -> u8
pub fn day(&self) -> u8
Get the database creation day. Convention is 1
for the first day
of the month.