Skip to content

Commit

Permalink
Merge pull request #33 from ipinfo/umar/update-examples-async
Browse files Browse the repository at this point in the history
update examples to async
  • Loading branch information
rm-Umar authored Mar 29, 2023
2 parents 6018ace + 7369412 commit 92fb948
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ipinfo"
description = "ipinfo: A Rust library for IPInfo"
version = "1.1.0"
version = "2.0.0"
authors = ["Amr Ali <[email protected]>", "Uman Shahzad <[email protected]>", "Umar Farooq <[email protected]>", "Fayzan Ahmad <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To use IPinfo, add the followinig to your `Cargo.toml` file.

```toml
[dependencies]
ipinfo = "1.1.0"
ipinfo = "2.0.0"
```

## Getting Started
Expand All @@ -41,8 +41,8 @@ cargo run --example lookup_batch -- <token>
The `lookup` example above looks more or less like
```rust
use ipinfo::{IpInfo, IpInfoConfig};

fn main() {
#[tokio::main]
async fn main() {
let config = IpInfoConfig {
token: Some("<token>".to_string()),
..Default::default()
Expand All @@ -51,7 +51,7 @@ fn main() {
let mut ipinfo = IpInfo::new(config)
.expect("should construct");

let res = ipinfo.lookup("8.8.8.8");
let res = ipinfo.lookup("8.8.8.8").await;
match res {
Ok(r) => {
println!("{} lookup result: {:?}", "8.8.8.8", r);
Expand Down
5 changes: 3 additions & 2 deletions examples/lookup.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::env;
use ipinfo::{IpInfo, IpInfoConfig};

fn main() {
#[tokio::main]
async fn main() {
let token = env::args().skip(1).next();

let config = IpInfoConfig {
Expand All @@ -12,7 +13,7 @@ fn main() {
let mut ipinfo = IpInfo::new(config)
.expect("should construct");

let res = ipinfo.lookup("8.8.8.8");
let res = ipinfo.lookup("8.8.8.8").await;
match res {
Ok(r) => {
println!("{} lookup result: {:?}", "8.8.8.8", r);
Expand Down
6 changes: 3 additions & 3 deletions examples/lookup_batch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::env;
use ipinfo::{IpInfo, IpInfoConfig};

fn main() {
#[tokio::main]
async fn main() {
let token = env::args().skip(1).next();

let config = IpInfoConfig {
Expand All @@ -12,7 +12,7 @@ fn main() {
let mut ipinfo = IpInfo::new(config)
.expect("should construct");

let res2 = ipinfo.lookup_batch(&["8.8.8.8", "4.2.2.4"]);
let res2 = ipinfo.lookup_batch(&["8.8.8.8", "4.2.2.4"]).await;

match res2 {
Ok(r) => {
Expand Down
17 changes: 11 additions & 6 deletions src/ipinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ impl IpInfo {
///
/// ```no_run
/// use ipinfo::IpInfo;
///
/// let mut ipinfo = IpInfo::new(Default::default()).expect("should construct");
/// let res = ipinfo.lookup_batch(&["8.8.8.8"]).expect("should run");
/// #[tokio::main]
/// async fn main() {
/// let mut ipinfo = IpInfo::new(Default::default()).expect("should construct");
/// let res = ipinfo.lookup_batch(&["8.8.8.8"]).await.expect("should run");
/// }
/// ```
pub async fn lookup_batch(
&mut self,
Expand Down Expand Up @@ -231,9 +233,12 @@ impl IpInfo {
///
/// ```no_run
/// use ipinfo::IpInfo;
///
/// let mut ipinfo = IpInfo::new(Default::default()).expect("should construct");
/// let res = ipinfo.lookup("8.8.8.8").expect("should run");
///
/// #[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");
/// }
/// ```
pub async fn lookup(
&mut self,
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
//!
//! ```no_run
//! use ipinfo::{IpInfo, IpInfoConfig};
//!
//! fn main() {
//! #[tokio::main]
//! async fn main() {
//! // Setup token and other configurations.
//! let config = IpInfoConfig { token: Some("my token".to_string()), ..Default::default() };
//!
//! // Setup IpInfo structure and start looking up IP addresses.
//! let mut ipinfo = IpInfo::new(config).expect("should construct");
//! let res = ipinfo.lookup("8.8.8.8");
//! let res = ipinfo.lookup("8.8.8.8").await;
//!
//! match res {
//! Ok(r) => println!("{}: {}", "8.8.8.8", r.hostname.as_ref().unwrap()),
Expand Down

0 comments on commit 92fb948

Please sign in to comment.