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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Database
impl RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnwindSafe for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more