Skip to content

Commit da9b031

Browse files
committed
refactor(lib): update to 2018 edition
1 parent 79ae89e commit da9b031

37 files changed

+358
-398
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ matrix:
1313
- rust: stable
1414
env: FEATURES="--no-default-features"
1515
# Minimum Supported Rust Version
16-
- rust: 1.27.0
16+
- rust: 1.31.0
1717
env: FEATURES="--no-default-features --features runtime" BUILD_ONLY="1"
1818

1919
before_script:

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ license = "MIT"
1010
authors = ["Sean McArthur <[email protected]>"]
1111
keywords = ["http", "hyper", "hyperium"]
1212
categories = ["network-programming", "web-programming::http-client", "web-programming::http-server"]
13+
edition = "2018"
1314

1415
publish = false
1516

benches/end_to_end.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ fn spawn_hello(rt: &mut Runtime, opts: &Opts) -> SocketAddr {
236236

237237
let body = opts.response_body;
238238
let srv = Server::bind(&addr)
239-
.http2_only(opts.http2);
239+
.http2_only(opts.http2)
240240
.http2_initial_stream_window_size_(opts.http2_stream_window)
241241
.http2_initial_connection_window_size_(opts.http2_conn_window)
242242
.serve(move || {

build.rs

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ use rustc_version::{version, Version};
44

55
fn main() {
66
let version = version().unwrap();
7-
if version >= Version::parse("1.30.0").unwrap() {
8-
println!("cargo:rustc-cfg=error_source");
9-
}
107
if version >= Version::parse("1.34.0").unwrap() {
118
println!("cargo:rustc-cfg=try_from");
129
}

src/body/body.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use tokio_buf::SizeHint;
99
use h2;
1010
use http::HeaderMap;
1111

12-
use common::Never;
12+
use crate::common::Never;
1313
use super::internal::{FullDataArg, FullDataRet};
1414
use super::{Chunk, Payload};
15-
use upgrade::OnUpgrade;
15+
use crate::upgrade::OnUpgrade;
1616

17-
type BodySender = mpsc::Sender<Result<Chunk, ::Error>>;
17+
type BodySender = mpsc::Sender<Result<Chunk, crate::Error>>;
1818

1919
/// A stream of `Chunk`s, used when receiving bodies.
2020
///
@@ -34,7 +34,7 @@ enum Kind {
3434
Chan {
3535
content_length: Option<u64>,
3636
abort_rx: oneshot::Receiver<()>,
37-
rx: mpsc::Receiver<Result<Chunk, ::Error>>,
37+
rx: mpsc::Receiver<Result<Chunk, crate::Error>>,
3838
},
3939
H2 {
4040
content_length: Option<u64>,
@@ -200,7 +200,7 @@ impl Body {
200200
}))
201201
}
202202

203-
fn poll_eof(&mut self) -> Poll<Option<Chunk>, ::Error> {
203+
fn poll_eof(&mut self) -> Poll<Option<Chunk>, crate::Error> {
204204
match self.take_delayed_eof() {
205205
Some(DelayEof::NotEof(mut delay)) => {
206206
match self.poll_inner() {
@@ -238,7 +238,7 @@ impl Body {
238238
}
239239
}
240240

241-
fn poll_inner(&mut self) -> Poll<Option<Chunk>, ::Error> {
241+
fn poll_inner(&mut self) -> Poll<Option<Chunk>, crate::Error> {
242242
match self.kind {
243243
Kind::Once(ref mut val) => Ok(Async::Ready(val.take())),
244244
Kind::Chan {
@@ -247,7 +247,7 @@ impl Body {
247247
ref mut abort_rx,
248248
} => {
249249
if let Ok(Async::Ready(())) = abort_rx.poll() {
250-
return Err(::Error::new_body_write("body write aborted"));
250+
return Err(crate::Error::new_body_write("body write aborted"));
251251
}
252252

253253
match rx.poll().expect("mpsc cannot error") {
@@ -267,16 +267,16 @@ impl Body {
267267
recv: ref mut h2, ..
268268
} => h2
269269
.poll()
270-
.map(|async| {
271-
async.map(|opt| {
270+
.map(|r#async| {
271+
r#async.map(|opt| {
272272
opt.map(|bytes| {
273273
let _ = h2.release_capacity().release_capacity(bytes.len());
274274
Chunk::from(bytes)
275275
})
276276
})
277277
})
278-
.map_err(::Error::new_body),
279-
Kind::Wrapped(ref mut s) => s.poll().map_err(::Error::new_body),
278+
.map_err(crate::Error::new_body),
279+
Kind::Wrapped(ref mut s) => s.poll().map_err(crate::Error::new_body),
280280
}
281281
}
282282
}
@@ -291,7 +291,7 @@ impl Default for Body {
291291

292292
impl Payload for Body {
293293
type Data = Chunk;
294-
type Error = ::Error;
294+
type Error = crate::Error;
295295

296296
fn poll_data(&mut self) -> Poll<Option<Self::Data>, Self::Error> {
297297
self.poll_eof()
@@ -301,7 +301,7 @@ impl Payload for Body {
301301
match self.kind {
302302
Kind::H2 {
303303
recv: ref mut h2, ..
304-
} => h2.poll_trailers().map_err(::Error::new_h2),
304+
} => h2.poll_trailers().map_err(crate::Error::new_h2),
305305
_ => Ok(Async::Ready(None)),
306306
}
307307
}
@@ -336,7 +336,7 @@ impl Payload for Body {
336336

337337
impl ::http_body::Body for Body {
338338
type Data = Chunk;
339-
type Error = ::Error;
339+
type Error = crate::Error;
340340

341341
fn poll_data(&mut self) -> Poll<Option<Self::Data>, Self::Error> {
342342
<Self as Payload>::poll_data(self)
@@ -366,7 +366,7 @@ impl ::http_body::Body for Body {
366366

367367
impl Stream for Body {
368368
type Item = Chunk;
369-
type Error = ::Error;
369+
type Error = crate::Error;
370370

371371
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
372372
self.poll_data()
@@ -395,13 +395,13 @@ impl fmt::Debug for Body {
395395

396396
impl Sender {
397397
/// Check to see if this `Sender` can send more data.
398-
pub fn poll_ready(&mut self) -> Poll<(), ::Error> {
398+
pub fn poll_ready(&mut self) -> Poll<(), crate::Error> {
399399
match self.abort_tx.poll_cancel() {
400-
Ok(Async::Ready(())) | Err(_) => return Err(::Error::new_closed()),
400+
Ok(Async::Ready(())) | Err(_) => return Err(crate::Error::new_closed()),
401401
Ok(Async::NotReady) => (),
402402
}
403403

404-
self.tx.poll_ready().map_err(|_| ::Error::new_closed())
404+
self.tx.poll_ready().map_err(|_| crate::Error::new_closed())
405405
}
406406

407407
/// Sends data on this channel.
@@ -422,14 +422,14 @@ impl Sender {
422422
let _ = self.abort_tx.send(());
423423
}
424424

425-
pub(crate) fn send_error(&mut self, err: ::Error) {
425+
pub(crate) fn send_error(&mut self, err: crate::Error) {
426426
let _ = self.tx.try_send(Err(err));
427427
}
428428
}
429429

430430
impl Sink for Sender {
431431
type SinkItem = Chunk;
432-
type SinkError = ::Error;
432+
type SinkError = crate::Error;
433433

434434
fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
435435
Ok(Async::Ready(()))
@@ -438,7 +438,7 @@ impl Sink for Sender {
438438
fn start_send(&mut self, msg: Chunk) -> StartSend<Self::SinkItem, Self::SinkError> {
439439
match self.poll_ready()? {
440440
Async::Ready(_) => {
441-
self.send_data(msg).map_err(|_| ::Error::new_closed())?;
441+
self.send_data(msg).map_err(|_| crate::Error::new_closed())?;
442442
Ok(AsyncSink::Ready)
443443
}
444444
Async::NotReady => Ok(AsyncSink::NotReady(msg)),

src/body/chunk.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ mod tests {
176176
let mut dst = Vec::with_capacity(128);
177177

178178
b.iter(|| {
179-
let chunk = ::Chunk::from(s);
179+
let chunk = crate::Chunk::from(s);
180180
dst.put(chunk);
181181
::test::black_box(&dst);
182182
dst.clear();

src/body/payload.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub trait Payload: Send + 'static {
6565
// The only thing a user *could* do is reference the method, but DON'T
6666
// DO THAT! :)
6767
#[doc(hidden)]
68-
fn __hyper_full_data(&mut self, FullDataArg) -> FullDataRet<Self::Data> {
68+
fn __hyper_full_data(&mut self, _: FullDataArg) -> FullDataRet<Self::Data> {
6969
FullDataRet(None)
7070
}
7171
}

src/client/conn.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ use futures::future::{self, Either, Executor};
1818
use h2;
1919
use tokio_io::{AsyncRead, AsyncWrite};
2020

21-
use body::Payload;
22-
use common::Exec;
23-
use upgrade::Upgraded;
24-
use proto;
21+
use crate::body::Payload;
22+
use crate::common::Exec;
23+
use crate::upgrade::Upgraded;
24+
use crate::proto;
2525
use super::dispatch;
26-
use {Body, Request, Response};
26+
use crate::{Body, Request, Response};
2727

2828
type Http1Dispatcher<T, B, R> = proto::dispatch::Dispatcher<
2929
proto::dispatch::Client<B>,
@@ -39,7 +39,7 @@ type ConnEither<T, B> = Either<
3939
/// Returns a `Handshake` future over some IO.
4040
///
4141
/// This is a shortcut for `Builder::new().handshake(io)`.
42-
pub fn handshake<T>(io: T) -> Handshake<T, ::Body>
42+
pub fn handshake<T>(io: T) -> Handshake<T, crate::Body>
4343
where
4444
T: AsyncRead + AsyncWrite + Send + 'static,
4545
{
@@ -98,7 +98,7 @@ pub struct Handshake<T, B> {
9898
pub struct ResponseFuture {
9999
// for now, a Box is used to hide away the internal `B`
100100
// that can be returned if canceled
101-
inner: Box<dyn Future<Item=Response<Body>, Error=::Error> + Send>,
101+
inner: Box<dyn Future<Item=Response<Body>, Error=crate::Error> + Send>,
102102
}
103103

104104
/// Deconstructed parts of a `Connection`.
@@ -145,7 +145,7 @@ impl<B> SendRequest<B>
145145
/// Polls to determine whether this sender can be used yet for a request.
146146
///
147147
/// If the associated connection is closed, this returns an Error.
148-
pub fn poll_ready(&mut self) -> Poll<(), ::Error> {
148+
pub fn poll_ready(&mut self) -> Poll<(), crate::Error> {
149149
self.dispatch.poll_ready()
150150
}
151151

@@ -235,7 +235,7 @@ where
235235
},
236236
Err(_req) => {
237237
debug!("connection was not ready");
238-
let err = ::Error::new_canceled().with("connection was not ready");
238+
let err = crate::Error::new_canceled().with("connection was not ready");
239239
Either::B(future::err(err))
240240
}
241241
};
@@ -245,7 +245,7 @@ where
245245
}
246246
}
247247

248-
pub(crate) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item = Response<Body>, Error = (::Error, Option<Request<B>>)>
248+
pub(crate) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item = Response<Body>, Error = (crate::Error, Option<Request<B>>)>
249249
where
250250
B: Send,
251251
{
@@ -262,7 +262,7 @@ where
262262
},
263263
Err(req) => {
264264
debug!("connection was not ready");
265-
let err = ::Error::new_canceled().with("connection was not ready");
265+
let err = crate::Error::new_canceled().with("connection was not ready");
266266
Either::B(future::err((err, Some(req))))
267267
}
268268
}
@@ -305,7 +305,7 @@ impl<B> Http2SendRequest<B>
305305
where
306306
B: Payload + 'static,
307307
{
308-
pub(super) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item=Response<Body>, Error=(::Error, Option<Request<B>>)>
308+
pub(super) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item=Response<Body>, Error=(crate::Error, Option<Request<B>>)>
309309
where
310310
B: Send,
311311
{
@@ -322,7 +322,7 @@ where
322322
},
323323
Err(req) => {
324324
debug!("connection was not ready");
325-
let err = ::Error::new_canceled().with("connection was not ready");
325+
let err = crate::Error::new_canceled().with("connection was not ready");
326326
Either::B(future::err((err, Some(req))))
327327
}
328328
}
@@ -380,7 +380,7 @@ where
380380
/// Use [`poll_fn`](https://docs.rs/futures/0.1.25/futures/future/fn.poll_fn.html)
381381
/// and [`try_ready!`](https://docs.rs/futures/0.1.25/futures/macro.try_ready.html)
382382
/// to work with this function; or use the `without_shutdown` wrapper.
383-
pub fn poll_without_shutdown(&mut self) -> Poll<(), ::Error> {
383+
pub fn poll_without_shutdown(&mut self) -> Poll<(), crate::Error> {
384384
match self.inner.as_mut().expect("already upgraded") {
385385
&mut Either::A(ref mut h1) => {
386386
h1.poll_without_shutdown()
@@ -393,9 +393,9 @@ where
393393

394394
/// Prevent shutdown of the underlying IO object at the end of service the request,
395395
/// instead run `into_parts`. This is a convenience wrapper over `poll_without_shutdown`.
396-
pub fn without_shutdown(self) -> impl Future<Item=Parts<T>, Error=::Error> {
396+
pub fn without_shutdown(self) -> impl Future<Item=Parts<T>, Error=crate::Error> {
397397
let mut conn = Some(self);
398-
::futures::future::poll_fn(move || -> ::Result<_> {
398+
::futures::future::poll_fn(move || -> crate::Result<_> {
399399
try_ready!(conn.as_mut().unwrap().poll_without_shutdown());
400400
Ok(conn.take().unwrap().into_parts().into())
401401
})
@@ -408,7 +408,7 @@ where
408408
B: Payload + 'static,
409409
{
410410
type Item = ();
411-
type Error = ::Error;
411+
type Error = crate::Error;
412412

413413
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
414414
match try_ready!(self.inner.poll()) {
@@ -552,7 +552,7 @@ where
552552
B: Payload + 'static,
553553
{
554554
type Item = (SendRequest<B>, Connection<T, B>);
555-
type Error = ::Error;
555+
type Error = crate::Error;
556556

557557
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
558558
let io = self.io.take().expect("polled more than once");
@@ -601,7 +601,7 @@ impl<T, B> fmt::Debug for Handshake<T, B> {
601601

602602
impl Future for ResponseFuture {
603603
type Item = Response<Body>;
604-
type Error = ::Error;
604+
type Error = crate::Error;
605605

606606
#[inline]
607607
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
@@ -620,7 +620,7 @@ impl fmt::Debug for ResponseFuture {
620620

621621
impl<B> Future for WhenReady<B> {
622622
type Item = SendRequest<B>;
623-
type Error = ::Error;
623+
type Error = crate::Error;
624624

625625
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
626626
let mut tx = self.tx.take().expect("polled after complete");

0 commit comments

Comments
 (0)