pub struct IpInfo { /* private fields */ }
Expand description
IPinfo requests context structure.
Implementations§
source§impl IpInfo
impl IpInfo
sourcepub fn new(config: IpInfoConfig) -> Result<Self, IpError>
pub fn new(config: IpInfoConfig) -> Result<Self, IpError>
Construct a new IpInfo structure.
Examples
use ipinfo::IpInfo;
let ipinfo = IpInfo::new(Default::default()).expect("should construct");
Examples found in repository?
More examples
examples/lookup.rs (line 13)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
async fn main() {
let token = env::args().skip(1).next();
let config = IpInfoConfig {
token,
..Default::default()
};
let mut ipinfo = IpInfo::new(config).expect("should construct");
let res = ipinfo.lookup("8.8.8.8").await;
match res {
Ok(r) => {
println!("{} lookup result: {:?}", "8.8.8.8", r);
}
Err(e) => println!("error occurred: {}", &e.to_string()),
}
}
examples/lookup_batch.rs (line 12)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
async fn main() {
let token = env::args().skip(1).next();
let config = IpInfoConfig {
token,
..Default::default()
};
let mut ipinfo = IpInfo::new(config).expect("should construct");
let res2 = ipinfo
.lookup_batch(&["8.8.8.8", "4.2.2.4"], BatchReqOpts::default())
.await;
match res2 {
Ok(r) => {
println!("{}: {:?}", "8.8.8.8", r["8.8.8.8"]);
println!("{}: {:?}", "4.2.2.4", r["4.2.2.4"]);
}
Err(e) => println!("error occurred: {}", &e.to_string()),
}
}
sourcepub async fn lookup_batch(
&mut self,
ips: &[&str],
batch_config: BatchReqOpts
) -> Result<HashMap<String, IpDetails>, IpError>
pub async fn lookup_batch( &mut self, ips: &[&str], batch_config: BatchReqOpts ) -> Result<HashMap<String, IpDetails>, IpError>
Lookup IPDetails for a list of one or more IP addresses.
Examples
use ipinfo::{IpInfo, BatchReqOpts};
#[tokio::main]
async fn main() {
let mut ipinfo = IpInfo::new(Default::default()).expect("should construct");
let res = ipinfo.lookup_batch(&["8.8.8.8"], BatchReqOpts::default()).await.expect("should run");
}
Examples found in repository?
examples/lookup_batch.rs (line 15)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
async fn main() {
let token = env::args().skip(1).next();
let config = IpInfoConfig {
token,
..Default::default()
};
let mut ipinfo = IpInfo::new(config).expect("should construct");
let res2 = ipinfo
.lookup_batch(&["8.8.8.8", "4.2.2.4"], BatchReqOpts::default())
.await;
match res2 {
Ok(r) => {
println!("{}: {:?}", "8.8.8.8", r["8.8.8.8"]);
println!("{}: {:?}", "4.2.2.4", r["4.2.2.4"]);
}
Err(e) => println!("error occurred: {}", &e.to_string()),
}
}
sourcepub async fn lookup(&mut self, ip: &str) -> Result<IpDetails, IpError>
pub async fn lookup(&mut self, ip: &str) -> Result<IpDetails, IpError>
looks up IPDetails for a single IP Address
Example
use ipinfo::IpInfo;
#[tokio::main]
async fn main() {
let mut ipinfo = IpInfo::new(Default::default()).expect("should construct");
let res = ipinfo.lookup("8.8.8.8").await.expect("should run");
}
Examples found in repository?
examples/lookup.rs (line 15)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
async fn main() {
let token = env::args().skip(1).next();
let config = IpInfoConfig {
token,
..Default::default()
};
let mut ipinfo = IpInfo::new(config).expect("should construct");
let res = ipinfo.lookup("8.8.8.8").await;
match res {
Ok(r) => {
println!("{} lookup result: {:?}", "8.8.8.8", r);
}
Err(e) => println!("error occurred: {}", &e.to_string()),
}
}
sourcepub async fn get_map(&self, ips: &[&str]) -> Result<String, IpError>
pub async fn get_map(&self, ips: &[&str]) -> Result<String, IpError>
Get a mapping of a list of IPs on a world map
Example
use ipinfo::IpInfo;
#[tokio::main]
async fn main() {
let ipinfo = IpInfo::new(Default::default()).expect("should construct");
let map_url = ipinfo.get_map(&["8.8.8.8", "4.2.2.4"]).await.expect("should run");
}
Auto Trait Implementations§
impl !RefUnwindSafe for IpInfo
impl Send for IpInfo
impl Sync for IpInfo
impl Unpin for IpInfo
impl !UnwindSafe for IpInfo
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