[−][src]Struct ip2proxy::Database
An IP2Proxy BIN database.
Methods
impl Database
[src]
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
[src]
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.
pub fn query(&self, addr: IpAddr, query: Columns) -> Result<Option<Row>>
[src]
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, Some(Row { proxy_type: Some(String::from("DCH")), country_short: Some(String::from("AU")), country_long: Some(String::from("Australia")), region: Some(String::from("Queensland")), city: Some(String::from("Brisbane")), isp: Some(String::from("Research Prefix for APNIC Labs")), ..Row::default() }));
Errors
- Error while reading from the source.
- Invalid row or string data.
pub fn header(&self) -> &Header
[src]
Get meta data from the database header.
Example
use ip2proxy::Database; let db = Database::open("data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN")?; let header = db.header(); assert_eq!(header.px(), 4); assert_eq!(header.year(), 16); // 2016 assert_eq!(header.month(), 11); // November assert_eq!(header.day(), 17); // 17th assert_eq!(header.rows_ipv4(), 150); assert_eq!(header.rows_ipv6(), 4);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnwindSafe for Database
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,