Skip to content

Commit

Permalink
refactor(lib): update to 2018 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jul 9, 2019
1 parent 79ae89e commit da9b031
Show file tree
Hide file tree
Showing 37 changed files with 358 additions and 398 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -13,7 +13,7 @@ matrix:
- rust: stable
env: FEATURES="--no-default-features"
# Minimum Supported Rust Version
- rust: 1.27.0
- rust: 1.31.0
env: FEATURES="--no-default-features --features runtime" BUILD_ONLY="1"

before_script:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -10,6 +10,7 @@ license = "MIT"
authors = ["Sean McArthur <sean@seanmonstar.com>"]
keywords = ["http", "hyper", "hyperium"]
categories = ["network-programming", "web-programming::http-client", "web-programming::http-server"]
edition = "2018"

publish = false

Expand Down
2 changes: 1 addition & 1 deletion benches/end_to_end.rs
Expand Up @@ -236,7 +236,7 @@ fn spawn_hello(rt: &mut Runtime, opts: &Opts) -> SocketAddr {

let body = opts.response_body;
let srv = Server::bind(&addr)
.http2_only(opts.http2);
.http2_only(opts.http2)
.http2_initial_stream_window_size_(opts.http2_stream_window)
.http2_initial_connection_window_size_(opts.http2_conn_window)
.serve(move || {
Expand Down
3 changes: 0 additions & 3 deletions build.rs
Expand Up @@ -4,9 +4,6 @@ use rustc_version::{version, Version};

fn main() {
let version = version().unwrap();
if version >= Version::parse("1.30.0").unwrap() {
println!("cargo:rustc-cfg=error_source");
}
if version >= Version::parse("1.34.0").unwrap() {
println!("cargo:rustc-cfg=try_from");
}
Expand Down
42 changes: 21 additions & 21 deletions src/body/body.rs
Expand Up @@ -9,12 +9,12 @@ use tokio_buf::SizeHint;
use h2;
use http::HeaderMap;

use common::Never;
use crate::common::Never;
use super::internal::{FullDataArg, FullDataRet};
use super::{Chunk, Payload};
use upgrade::OnUpgrade;
use crate::upgrade::OnUpgrade;

type BodySender = mpsc::Sender<Result<Chunk, ::Error>>;
type BodySender = mpsc::Sender<Result<Chunk, crate::Error>>;

/// A stream of `Chunk`s, used when receiving bodies.
///
Expand All @@ -34,7 +34,7 @@ enum Kind {
Chan {
content_length: Option<u64>,
abort_rx: oneshot::Receiver<()>,
rx: mpsc::Receiver<Result<Chunk, ::Error>>,
rx: mpsc::Receiver<Result<Chunk, crate::Error>>,
},
H2 {
content_length: Option<u64>,
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Body {
}))
}

fn poll_eof(&mut self) -> Poll<Option<Chunk>, ::Error> {
fn poll_eof(&mut self) -> Poll<Option<Chunk>, crate::Error> {
match self.take_delayed_eof() {
Some(DelayEof::NotEof(mut delay)) => {
match self.poll_inner() {
Expand Down Expand Up @@ -238,7 +238,7 @@ impl Body {
}
}

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

match rx.poll().expect("mpsc cannot error") {
Expand All @@ -267,16 +267,16 @@ impl Body {
recv: ref mut h2, ..
} => h2
.poll()
.map(|async| {
async.map(|opt| {
.map(|r#async| {
r#async.map(|opt| {
opt.map(|bytes| {
let _ = h2.release_capacity().release_capacity(bytes.len());
Chunk::from(bytes)
})
})
})
.map_err(::Error::new_body),
Kind::Wrapped(ref mut s) => s.poll().map_err(::Error::new_body),
.map_err(crate::Error::new_body),
Kind::Wrapped(ref mut s) => s.poll().map_err(crate::Error::new_body),
}
}
}
Expand All @@ -291,7 +291,7 @@ impl Default for Body {

impl Payload for Body {
type Data = Chunk;
type Error = ::Error;
type Error = crate::Error;

fn poll_data(&mut self) -> Poll<Option<Self::Data>, Self::Error> {
self.poll_eof()
Expand All @@ -301,7 +301,7 @@ impl Payload for Body {
match self.kind {
Kind::H2 {
recv: ref mut h2, ..
} => h2.poll_trailers().map_err(::Error::new_h2),
} => h2.poll_trailers().map_err(crate::Error::new_h2),
_ => Ok(Async::Ready(None)),
}
}
Expand Down Expand Up @@ -336,7 +336,7 @@ impl Payload for Body {

impl ::http_body::Body for Body {
type Data = Chunk;
type Error = ::Error;
type Error = crate::Error;

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

impl Stream for Body {
type Item = Chunk;
type Error = ::Error;
type Error = crate::Error;

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

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

self.tx.poll_ready().map_err(|_| ::Error::new_closed())
self.tx.poll_ready().map_err(|_| crate::Error::new_closed())
}

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

pub(crate) fn send_error(&mut self, err: ::Error) {
pub(crate) fn send_error(&mut self, err: crate::Error) {
let _ = self.tx.try_send(Err(err));
}
}

impl Sink for Sender {
type SinkItem = Chunk;
type SinkError = ::Error;
type SinkError = crate::Error;

fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
Ok(Async::Ready(()))
Expand All @@ -438,7 +438,7 @@ impl Sink for Sender {
fn start_send(&mut self, msg: Chunk) -> StartSend<Self::SinkItem, Self::SinkError> {
match self.poll_ready()? {
Async::Ready(_) => {
self.send_data(msg).map_err(|_| ::Error::new_closed())?;
self.send_data(msg).map_err(|_| crate::Error::new_closed())?;
Ok(AsyncSink::Ready)
}
Async::NotReady => Ok(AsyncSink::NotReady(msg)),
Expand Down
2 changes: 1 addition & 1 deletion src/body/chunk.rs
Expand Up @@ -176,7 +176,7 @@ mod tests {
let mut dst = Vec::with_capacity(128);

b.iter(|| {
let chunk = ::Chunk::from(s);
let chunk = crate::Chunk::from(s);
dst.put(chunk);
::test::black_box(&dst);
dst.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/body/payload.rs
Expand Up @@ -65,7 +65,7 @@ pub trait Payload: Send + 'static {
// The only thing a user *could* do is reference the method, but DON'T
// DO THAT! :)
#[doc(hidden)]
fn __hyper_full_data(&mut self, FullDataArg) -> FullDataRet<Self::Data> {
fn __hyper_full_data(&mut self, _: FullDataArg) -> FullDataRet<Self::Data> {
FullDataRet(None)
}
}
Expand Down
40 changes: 20 additions & 20 deletions src/client/conn.rs
Expand Up @@ -18,12 +18,12 @@ use futures::future::{self, Either, Executor};
use h2;
use tokio_io::{AsyncRead, AsyncWrite};

use body::Payload;
use common::Exec;
use upgrade::Upgraded;
use proto;
use crate::body::Payload;
use crate::common::Exec;
use crate::upgrade::Upgraded;
use crate::proto;
use super::dispatch;
use {Body, Request, Response};
use crate::{Body, Request, Response};

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

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

Expand Down Expand Up @@ -235,7 +235,7 @@ where
},
Err(_req) => {
debug!("connection was not ready");
let err = ::Error::new_canceled().with("connection was not ready");
let err = crate::Error::new_canceled().with("connection was not ready");
Either::B(future::err(err))
}
};
Expand All @@ -245,7 +245,7 @@ where
}
}

pub(crate) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item = Response<Body>, Error = (::Error, Option<Request<B>>)>
pub(crate) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item = Response<Body>, Error = (crate::Error, Option<Request<B>>)>
where
B: Send,
{
Expand All @@ -262,7 +262,7 @@ where
},
Err(req) => {
debug!("connection was not ready");
let err = ::Error::new_canceled().with("connection was not ready");
let err = crate::Error::new_canceled().with("connection was not ready");
Either::B(future::err((err, Some(req))))
}
}
Expand Down Expand Up @@ -305,7 +305,7 @@ impl<B> Http2SendRequest<B>
where
B: Payload + 'static,
{
pub(super) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item=Response<Body>, Error=(::Error, Option<Request<B>>)>
pub(super) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item=Response<Body>, Error=(crate::Error, Option<Request<B>>)>
where
B: Send,
{
Expand All @@ -322,7 +322,7 @@ where
},
Err(req) => {
debug!("connection was not ready");
let err = ::Error::new_canceled().with("connection was not ready");
let err = crate::Error::new_canceled().with("connection was not ready");
Either::B(future::err((err, Some(req))))
}
}
Expand Down Expand Up @@ -380,7 +380,7 @@ where
/// Use [`poll_fn`](https://docs.rs/futures/0.1.25/futures/future/fn.poll_fn.html)
/// and [`try_ready!`](https://docs.rs/futures/0.1.25/futures/macro.try_ready.html)
/// to work with this function; or use the `without_shutdown` wrapper.
pub fn poll_without_shutdown(&mut self) -> Poll<(), ::Error> {
pub fn poll_without_shutdown(&mut self) -> Poll<(), crate::Error> {
match self.inner.as_mut().expect("already upgraded") {
&mut Either::A(ref mut h1) => {
h1.poll_without_shutdown()
Expand All @@ -393,9 +393,9 @@ where

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

fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
match try_ready!(self.inner.poll()) {
Expand Down Expand Up @@ -552,7 +552,7 @@ where
B: Payload + 'static,
{
type Item = (SendRequest<B>, Connection<T, B>);
type Error = ::Error;
type Error = crate::Error;

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

impl Future for ResponseFuture {
type Item = Response<Body>;
type Error = ::Error;
type Error = crate::Error;

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

impl<B> Future for WhenReady<B> {
type Item = SendRequest<B>;
type Error = ::Error;
type Error = crate::Error;

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

0 comments on commit da9b031

Please sign in to comment.