diff --git a/.travis.yml b/.travis.yml index 15c6e32..d91bcbb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: rust rust: - - nightly-2019-04-16 + - nightly-2019-04-25 before_script: | rustup component add rustfmt clippy diff --git a/Cargo.toml b/Cargo.toml index b8fd647..5e70f34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,4 @@ http = "0.1.17" http-service-hyper = { path = "http-service-hyper", version = "0.1.1" } [dependencies.futures-preview] -version = "0.3.0-alpha.14" +version = "0.3.0-alpha.15" diff --git a/examples/simple_response.rs b/examples/simple_response.rs index f519eec..e4431ca 100644 --- a/examples/simple_response.rs +++ b/examples/simple_response.rs @@ -1,4 +1,4 @@ -#![feature(futures_api, async_await, await_macro, existential_type)] +#![feature(async_await, await_macro, existential_type)] use futures::future::{self, FutureObj}; use http_service::{HttpService, Response}; diff --git a/http-service-hyper/Cargo.toml b/http-service-hyper/Cargo.toml index a2e1156..87c5682 100644 --- a/http-service-hyper/Cargo.toml +++ b/http-service-hyper/Cargo.toml @@ -18,4 +18,4 @@ hyper = "0.12.27" [dependencies.futures-preview] features = ["compat"] -version = "0.3.0-alpha.14" +version = "0.3.0-alpha.15" diff --git a/http-service-hyper/src/lib.rs b/http-service-hyper/src/lib.rs index 9722e81..8f9c34d 100644 --- a/http-service-hyper/src/lib.rs +++ b/http-service-hyper/src/lib.rs @@ -4,11 +4,11 @@ #![deny(missing_debug_implementations, nonstandard_style)] #![warn(missing_docs, missing_doc_code_examples)] #![cfg_attr(test, deny(warnings))] -#![feature(futures_api, async_await, await_macro)] +#![feature(async_await, await_macro)] use futures::{ compat::{Compat, Compat01As03, Future01CompatExt}, - future::FutureObj, + future::BoxFuture, prelude::*, }; use http_service::{Body, HttpService}; @@ -33,20 +33,21 @@ where type ResBody = hyper::Body; type Error = std::io::Error; type Service = WrapConnection; - type Future = Compat>>; + type Future = Compat>>; type MakeError = std::io::Error; fn make_service(&mut self, _ctx: Ctx) -> Self::Future { let service = self.service.clone(); let error = std::io::Error::from(std::io::ErrorKind::Other); - FutureObj::new(Box::new(async move { + async move { let connection = await!(service.connect().into_future()).map_err(|_| error)?; Ok(WrapConnection { service, connection, }) - })) - .compat() + } + .boxed() + .compat() } } @@ -57,7 +58,7 @@ where type ReqBody = hyper::Body; type ResBody = hyper::Body; type Error = std::io::Error; - type Future = Compat, Self::Error>>>; + type Future = Compat, Self::Error>>>; fn call(&mut self, req: http::Request) -> Self::Future { let error = std::io::Error::from(std::io::ErrorKind::Other); @@ -70,11 +71,12 @@ where }); let fut = self.service.respond(&mut self.connection, req); - FutureObj::new(Box::new(async move { + async move { let res: http::Response<_> = await!(fut.into_future()).map_err(|_| error)?; Ok(res.map(|body| hyper::Body::wrap_stream(body.compat()))) - })) - .compat() + } + .boxed() + .compat() } } diff --git a/http-service-mock/Cargo.toml b/http-service-mock/Cargo.toml index 3349822..3d1aad3 100644 --- a/http-service-mock/Cargo.toml +++ b/http-service-mock/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/rust-net-web/http-service" version = "0.1.1" [dependencies] -http-service = "0.1.5" +http-service = { version = "0.1.5", path = ".." } [dependencies.futures-preview] -version = "0.3.0-alpha.14" \ No newline at end of file +version = "0.3.0-alpha.15" diff --git a/http-service-mock/src/lib.rs b/http-service-mock/src/lib.rs index e2f1ec3..f5e95af 100644 --- a/http-service-mock/src/lib.rs +++ b/http-service-mock/src/lib.rs @@ -4,7 +4,7 @@ #![deny(missing_debug_implementations, nonstandard_style)] #![warn(missing_docs, missing_doc_code_examples)] #![cfg_attr(test, deny(warnings))] -#![feature(futures_api, async_await)] +#![feature(async_await)] use futures::{executor::block_on, prelude::*}; use http_service::{HttpService, Request, Response}; diff --git a/src/lib.rs b/src/lib.rs index cdbffb2..61c71e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,17 +57,18 @@ #![deny(missing_debug_implementations, nonstandard_style)] #![warn(missing_docs, missing_doc_code_examples)] #![cfg_attr(test, deny(warnings))] -#![feature(futures_api, async_await, await_macro, arbitrary_self_types)] +#![feature(async_await, await_macro, arbitrary_self_types)] use bytes::Bytes; use futures::{ future, prelude::*, - stream::{self, StreamObj}, + stream::{self, BoxStream}, task::Context, Poll, }; +use std::fmt; use std::marker::Unpin; use std::pin::Pin; @@ -76,9 +77,8 @@ use std::pin::Pin; /// A body is a stream of `Bytes` values, which are shared handles to byte buffers. /// Both `Body` and `Bytes` values can be easily created from standard owned byte buffer types /// like `Vec` or `String`, using the `From` trait. -#[derive(Debug)] pub struct Body { - stream: StreamObj<'static, Result>, + stream: BoxStream<'static, Result>, } impl Body { @@ -92,12 +92,11 @@ impl Body { where S: Stream> + Send + 'static, { - Self { - stream: StreamObj::new(Box::new(s)), - } + Self { stream: s.boxed() } } /// Reads the stream into a new `Vec`. + #[allow(clippy::wrong_self_convention)] // https://github.com/rust-lang/rust-clippy/issues/4037 pub async fn into_vec(mut self) -> std::io::Result> { let mut bytes = Vec::new(); while let Some(chunk) = await!(self.next()) { @@ -118,7 +117,13 @@ impl Unpin for Body {} impl Stream for Body { type Item = Result; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.stream).poll_next(cx) + self.stream.poll_next_unpin(cx) + } +} + +impl fmt::Debug for Body { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Body").finish() } }