Skip to content
This repository was archived by the owner on Jun 21, 2020. It is now read-only.

Commit 64b65fb

Browse files
committed
Update for futures v0.3.0-alpha.15
Remove FutureObj/StreamObj usage and futures_api feature.
1 parent 2d11bbf commit 64b65fb

File tree

7 files changed

+28
-20
lines changed

7 files changed

+28
-20
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ http = "0.1.17"
1818
http-service-hyper = { path = "http-service-hyper", version = "0.1.1" }
1919

2020
[dependencies.futures-preview]
21-
version = "0.3.0-alpha.14"
21+
version = "0.3.0-alpha.15"

examples/simple_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(futures_api, async_await, await_macro, existential_type)]
1+
#![feature(async_await, await_macro, existential_type)]
22

33
use futures::future::{self, FutureObj};
44
use http_service::{HttpService, Response};

http-service-hyper/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ hyper = "0.12.27"
1818

1919
[dependencies.futures-preview]
2020
features = ["compat"]
21-
version = "0.3.0-alpha.14"
21+
version = "0.3.0-alpha.15"

http-service-hyper/src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#![deny(missing_debug_implementations, nonstandard_style)]
55
#![warn(missing_docs, missing_doc_code_examples)]
66
#![cfg_attr(test, deny(warnings))]
7-
#![feature(futures_api, async_await, await_macro)]
7+
#![feature(async_await, await_macro)]
88

99
use futures::{
1010
compat::{Compat, Compat01As03, Future01CompatExt},
11-
future::FutureObj,
11+
future::BoxFuture,
1212
prelude::*,
1313
};
1414
use http_service::{Body, HttpService};
@@ -33,19 +33,20 @@ where
3333
type ResBody = hyper::Body;
3434
type Error = std::io::Error;
3535
type Service = WrapConnection<H>;
36-
type Future = Compat<FutureObj<'static, Result<Self::Service, Self::Error>>>;
36+
type Future = Compat<BoxFuture<'static, Result<Self::Service, Self::Error>>>;
3737
type MakeError = std::io::Error;
3838

3939
fn make_service(&mut self, _ctx: Ctx) -> Self::Future {
4040
let service = self.service.clone();
4141
let error = std::io::Error::from(std::io::ErrorKind::Other);
42-
FutureObj::new(Box::new(async move {
42+
async move {
4343
let connection = await!(service.connect().into_future()).map_err(|_| error)?;
4444
Ok(WrapConnection {
4545
service,
4646
connection,
4747
})
48-
}))
48+
}
49+
.boxed()
4950
.compat()
5051
}
5152
}
@@ -57,7 +58,7 @@ where
5758
type ReqBody = hyper::Body;
5859
type ResBody = hyper::Body;
5960
type Error = std::io::Error;
60-
type Future = Compat<FutureObj<'static, Result<http::Response<hyper::Body>, Self::Error>>>;
61+
type Future = Compat<BoxFuture<'static, Result<http::Response<hyper::Body>, Self::Error>>>;
6162

6263
fn call(&mut self, req: http::Request<hyper::Body>) -> Self::Future {
6364
let error = std::io::Error::from(std::io::ErrorKind::Other);
@@ -70,10 +71,11 @@ where
7071
});
7172
let fut = self.service.respond(&mut self.connection, req);
7273

73-
FutureObj::new(Box::new(async move {
74+
async move {
7475
let res: http::Response<_> = await!(fut.into_future()).map_err(|_| error)?;
7576
Ok(res.map(|body| hyper::Body::wrap_stream(body.compat())))
76-
}))
77+
}
78+
.boxed()
7779
.compat()
7880
}
7981
}

http-service-mock/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repository = "https://github.com/rust-net-web/http-service"
1111
version = "0.1.1"
1212

1313
[dependencies]
14-
http-service = "0.1.5"
14+
http-service = { version = "0.1.5", path = ".." }
1515

1616
[dependencies.futures-preview]
17-
version = "0.3.0-alpha.14"
17+
version = "0.3.0-alpha.15"

http-service-mock/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![deny(missing_debug_implementations, nonstandard_style)]
55
#![warn(missing_docs, missing_doc_code_examples)]
66
#![cfg_attr(test, deny(warnings))]
7-
#![feature(futures_api, async_await)]
7+
#![feature(async_await)]
88

99
use futures::{executor::block_on, prelude::*};
1010
use http_service::{HttpService, Request, Response};

src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,18 @@
5757
#![deny(missing_debug_implementations, nonstandard_style)]
5858
#![warn(missing_docs, missing_doc_code_examples)]
5959
#![cfg_attr(test, deny(warnings))]
60-
#![feature(futures_api, async_await, await_macro, arbitrary_self_types)]
60+
#![feature(async_await, await_macro, arbitrary_self_types)]
6161

6262
use bytes::Bytes;
6363
use futures::{
6464
future,
6565
prelude::*,
66-
stream::{self, StreamObj},
66+
stream::{self, BoxStream},
6767
task::Context,
6868
Poll,
6969
};
7070

71+
use std::fmt;
7172
use std::marker::Unpin;
7273
use std::pin::Pin;
7374

@@ -76,9 +77,8 @@ use std::pin::Pin;
7677
/// A body is a stream of `Bytes` values, which are shared handles to byte buffers.
7778
/// Both `Body` and `Bytes` values can be easily created from standard owned byte buffer types
7879
/// like `Vec<u8>` or `String`, using the `From` trait.
79-
#[derive(Debug)]
8080
pub struct Body {
81-
stream: StreamObj<'static, Result<Bytes, std::io::Error>>,
81+
stream: BoxStream<'static, Result<Bytes, std::io::Error>>,
8282
}
8383

8484
impl Body {
@@ -93,7 +93,7 @@ impl Body {
9393
S: Stream<Item = Result<Bytes, std::io::Error>> + Send + 'static,
9494
{
9595
Self {
96-
stream: StreamObj::new(Box::new(s)),
96+
stream: s.boxed(),
9797
}
9898
}
9999

@@ -118,7 +118,13 @@ impl Unpin for Body {}
118118
impl Stream for Body {
119119
type Item = Result<Bytes, std::io::Error>;
120120
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
121-
Pin::new(&mut self.stream).poll_next(cx)
121+
self.stream.poll_next_unpin(cx)
122+
}
123+
}
124+
125+
impl fmt::Debug for Body {
126+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127+
f.debug_struct("Body").finish()
122128
}
123129
}
124130

0 commit comments

Comments
 (0)