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:
		| @@ -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(()) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user