-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
async.rs
35 lines (29 loc) · 843 Bytes
/
async.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#![deny(warnings)]
extern crate futures;
extern crate reqwest;
extern crate tokio;
use std::mem;
use std::io::{self, Cursor};
use futures::{Future, Stream};
use reqwest::async::{Client, Decoder};
fn fetch() -> impl Future<Item=(), Error=()> {
Client::new()
.get("https://hyper.rs")
.send()
.and_then(|mut res| {
println!("{}", res.status());
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());
}