Struct fixerio::AsyncApi [] [src]

pub struct AsyncApi { /* fields omitted */ }

Asynchronous API for sending requests

Methods

impl AsyncApi
[src]

Create a new instance.

Perform request with timeout.

Examples

use fixerio::{Config, Currency, AsyncApi};
use tokio_core::reactor::Core;
use std::time::Duration;

fn main() {
    let mut core = Core::new().expect("Error creating core");
    let handle = core.handle();

    let api = AsyncApi::new(&handle);

    let config = Config::new(Currency::USD);

    let work = api.get_timeout(&config, Duration::from_secs(5));

    let rates = core.run(work).expect("Error retrieving rates");

    match rates {
        Some(x) => println!("{:?}", x),
        _ => println!("Request timed out")
    };
}

Perform request.

Examples

use fixerio::{Config, Currency, AsyncApi};
use tokio_core::reactor::Core;
use std::time::Duration;

fn main() {
    let mut core = Core::new().expect("Error creating core");
    let handle = core.handle();

    // Get the latest exchange rates for USD
    let api = AsyncApi::new(&handle);

    let config = Config::new(Currency::USD);
    let work = api.get(&config);

    println!("{:?}", core.run(work).expect("Error retrieving rates"));
}