remote tokio-core dependency
This commit is contained in:
@@ -27,7 +27,6 @@ native-tls = "0.1.5"
|
|||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde_urlencoded = "0.5"
|
serde_urlencoded = "0.5"
|
||||||
tokio-core = "0.1.17"
|
|
||||||
tokio = "0.1.7"
|
tokio = "0.1.7"
|
||||||
tokio-io = "0.1"
|
tokio-io = "0.1"
|
||||||
tokio-tls = "0.1"
|
tokio-tls = "0.1"
|
||||||
|
|||||||
@@ -1,43 +1,35 @@
|
|||||||
#![allow(warnings)] // remove when error_chain is fixed
|
#![deny(warnings)]
|
||||||
|
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
extern crate tokio_core;
|
extern crate tokio;
|
||||||
#[macro_use]
|
|
||||||
extern crate error_chain;
|
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::io::{self, Cursor};
|
use std::io::{self, Cursor};
|
||||||
use futures::{Future, Stream};
|
use futures::{Future, Stream};
|
||||||
use reqwest::unstable::async::{Client, Decoder};
|
use reqwest::unstable::async::{Client, Decoder};
|
||||||
|
|
||||||
error_chain! {
|
|
||||||
foreign_links {
|
|
||||||
ReqError(reqwest::Error);
|
|
||||||
IoError(io::Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run() -> Result<()> {
|
fn fetch() -> impl Future<Item=(), Error=()> {
|
||||||
let mut core = tokio_core::reactor::Core::new()?;
|
Client::new()
|
||||||
let client = Client::new();
|
.get("https://hyper.rs")
|
||||||
|
|
||||||
let work = client.get("https://hyper.rs")
|
|
||||||
.send()
|
.send()
|
||||||
.map_err(|e| Error::from(e))
|
|
||||||
.and_then(|mut res| {
|
.and_then(|mut res| {
|
||||||
println!("{}", res.status());
|
println!("{}", res.status());
|
||||||
|
|
||||||
let body = mem::replace(res.body_mut(), Decoder::empty());
|
let body = mem::replace(res.body_mut(), Decoder::empty());
|
||||||
body.concat2().map_err(Into::into)
|
body.concat2()
|
||||||
})
|
})
|
||||||
.and_then(|body| {
|
.map_err(|err| println!("request error: {}", err))
|
||||||
|
.map(|body| {
|
||||||
let mut body = Cursor::new(body);
|
let mut body = Cursor::new(body);
|
||||||
io::copy(&mut body, &mut io::stdout()).map_err(Into::into)
|
io::copy(&mut body, &mut io::stdout())
|
||||||
});
|
.map_err(|err| {
|
||||||
|
println!("stdout error: {}", err);
|
||||||
core.run(work)?;
|
});
|
||||||
Ok(())
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
quick_main!(run);
|
fn main() {
|
||||||
|
tokio::run(fetch());
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,26 +29,6 @@ static DEFAULT_USER_AGENT: &'static str =
|
|||||||
///
|
///
|
||||||
/// The `Client` holds a connection pool internally, so it is advised that
|
/// The `Client` holds a connection pool internally, so it is advised that
|
||||||
/// you create one and **reuse** it.
|
/// you create one and **reuse** it.
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # #[cfg(features = "unstable")]
|
|
||||||
/// # fn run() -> Result<(), Box<::std::error::Error>> {
|
|
||||||
/// # extern crate tokio_core;
|
|
||||||
/// # extern crate futures;
|
|
||||||
/// use futures::Future;
|
|
||||||
/// use tokio_core::reactor::Core;
|
|
||||||
/// use reqwest::unstable::async::Client;
|
|
||||||
///
|
|
||||||
/// let mut core = Core::new()?;
|
|
||||||
/// let client = Client::new(&core.handle());
|
|
||||||
/// let fut = client.get("http://httpbin.org/").send();
|
|
||||||
/// core.run(fut)?;
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
|
|||||||
Reference in New Issue
Block a user