refactor all to async/await (#617)

Co-authored-by: Danny Browning <danny.browning@protectwise.com>
Co-authored-by: Daniel Eades <danieleades@hotmail.com>
This commit is contained in:
Sean McArthur
2019-09-06 17:22:56 -07:00
committed by GitHub
parent d7fcd8ac2e
commit ba7b2a754e
30 changed files with 1106 additions and 1430 deletions

View File

@@ -1,29 +1,16 @@
#![deny(warnings)]
use futures::{Future, Stream};
use reqwest::r#async::{Client, Decoder};
use std::io::{self, Cursor};
use std::mem;
use reqwest::r#async::Client;
fn fetch() -> impl Future<Item = (), Error = ()> {
Client::new()
.get("https://hyper.rs")
.send()
.and_then(|mut res| {
println!("{}", res.status());
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let mut res = Client::new().get("https://hyper.rs").send().await?;
let body = mem::replace(res.body_mut(), Decoder::empty());
body.concat2()
})
.map_err(|err| println!("request error: {}", err))
.map(|body| {
let mut body = Cursor::new(body);
let _ = io::copy(&mut body, &mut io::stdout()).map_err(|err| {
println!("stdout error: {}", err);
});
})
}
fn main() {
tokio::run(fetch());
println!("Status: {}", res.status());
let body = res.text().await?;
println!("Body:\n\n{}", body);
Ok(())
}