Struct ipinfo::IpInfo

source ·
pub struct IpInfo { /* private fields */ }
Expand description

IPinfo requests context structure.

Implementations§

source§

impl IpInfo

source

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?
examples/get_map.rs (line 5)
4
5
6
7
8
9
10
11
12
13
14
async fn main() {
    let ipinfo = IpInfo::new(Default::default()).expect("should construct");

    let res = ipinfo.get_map(&["8.8.8.8", "4.2.2.4"]).await;
    match res {
        Ok(r) => {
            println!("Map URL: {}", r);
        }
        Err(e) => println!("error occurred: {}", &e.to_string()),
    }
}
More examples
Hide additional 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()),
    }
}
source

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()),
    }
}
source

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()),
    }
}
source

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");
}
Examples found in repository?
examples/get_map.rs (line 7)
4
5
6
7
8
9
10
11
12
13
14
async fn main() {
    let ipinfo = IpInfo::new(Default::default()).expect("should construct");

    let res = ipinfo.get_map(&["8.8.8.8", "4.2.2.4"]).await;
    match res {
        Ok(r) => {
            println!("Map URL: {}", r);
        }
        Err(e) => println!("error occurred: {}", &e.to_string()),
    }
}

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more