style(lib): use rust 2018 edition idioms (#1910)

This commit is contained in:
lzutao
2019-08-22 01:22:07 +07:00
committed by Sean McArthur
parent ae75b3a732
commit fc7f81b67c
38 changed files with 90 additions and 146 deletions

View File

@@ -1,7 +1,5 @@
#![deny(warnings)] #![deny(warnings)]
extern crate hyper; #![warn(rust_2018_idioms)]
extern crate pretty_env_logger;
use std::env; use std::env;
use std::io::{self, Write}; use std::io::{self, Write};

View File

@@ -1,9 +1,8 @@
#![deny(warnings)] #![deny(warnings)]
extern crate hyper; #![warn(rust_2018_idioms)]
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
extern crate serde;
extern crate serde_json;
use hyper::Client; use hyper::Client;
use futures_util::TryStreamExt; use futures_util::TryStreamExt;

View File

@@ -1,6 +1,5 @@
#![deny(warnings)] #![deny(warnings)]
extern crate hyper; #![warn(rust_2018_idioms)]
extern crate pretty_env_logger;
use hyper::{Body, Request, Response, Server}; use hyper::{Body, Request, Response, Server};
use hyper::service::{service_fn, make_service_fn}; use hyper::service::{service_fn, make_service_fn};

View File

@@ -1,7 +1,5 @@
// #![deny(warnings)] // FIXME: https://github.com/rust-lang/rust/issues/62411 // #![deny(warnings)] // FIXME: https://github.com/rust-lang/rust/issues/62411
extern crate hyper; #![warn(rust_2018_idioms)]
extern crate pretty_env_logger;
extern crate url;
use hyper::{Body, Method, Request, Response, Server, StatusCode}; use hyper::{Body, Method, Request, Response, Server, StatusCode};
use hyper::service::{service_fn, make_service_fn}; use hyper::service::{service_fn, make_service_fn};

View File

@@ -7,7 +7,6 @@ use futures_core::{Stream, TryStream};
use futures_channel::{mpsc, oneshot}; use futures_channel::{mpsc, oneshot};
use futures_util::TryStreamExt; use futures_util::TryStreamExt;
//use tokio_buf::SizeHint; //use tokio_buf::SizeHint;
use h2;
use http::HeaderMap; use http::HeaderMap;
use crate::common::{Future, Never, Pin, Poll, task}; use crate::common::{Future, Never, Pin, Poll, task};
@@ -130,7 +129,6 @@ impl Body {
/// ///
/// ``` /// ```
/// # use hyper::Body; /// # use hyper::Body;
/// # use futures_util;
/// # fn main() { /// # fn main() {
/// let chunks: Vec<Result<_, ::std::io::Error>> = vec![ /// let chunks: Vec<Result<_, ::std::io::Error>> = vec![
/// Ok("hello"), /// Ok("hello"),
@@ -346,7 +344,7 @@ impl Payload for Body {
} }
impl fmt::Debug for Body { impl fmt::Debug for Body {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[derive(Debug)] #[derive(Debug)]
struct Streaming; struct Streaming;
#[derive(Debug)] #[derive(Debug)]

View File

@@ -113,7 +113,7 @@ impl AsRef<[u8]> for Chunk {
impl fmt::Debug for Chunk { impl fmt::Debug for Chunk {
#[inline] #[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.bytes, f) fmt::Debug::fmt(&self.bytes, f)
} }
} }

View File

@@ -14,7 +14,6 @@ use std::sync::Arc;
use bytes::Bytes; use bytes::Bytes;
use futures_util::future::{self, Either, FutureExt as _}; use futures_util::future::{self, Either, FutureExt as _};
use h2;
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
use crate::body::Payload; use crate::body::Payload;
@@ -258,7 +257,7 @@ impl<T, B> Service for SendRequest<T, B> {
*/ */
impl<B> fmt::Debug for SendRequest<B> { impl<B> fmt::Debug for SendRequest<B> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SendRequest") f.debug_struct("SendRequest")
.finish() .finish()
} }
@@ -305,7 +304,7 @@ where
} }
impl<B> fmt::Debug for Http2SendRequest<B> { impl<B> fmt::Debug for Http2SendRequest<B> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Http2SendRequest") f.debug_struct("Http2SendRequest")
.finish() .finish()
} }
@@ -410,7 +409,7 @@ where
T: AsyncRead + AsyncWrite + fmt::Debug + Send + 'static, T: AsyncRead + AsyncWrite + fmt::Debug + Send + 'static,
B: Payload + 'static, B: Payload + 'static,
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Connection") f.debug_struct("Connection")
.finish() .finish()
} }
@@ -575,7 +574,7 @@ impl Future for ResponseFuture {
} }
impl fmt::Debug for ResponseFuture { impl fmt::Debug for ResponseFuture {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ResponseFuture") f.debug_struct("ResponseFuture")
.finish() .finish()
} }

View File

@@ -75,13 +75,13 @@ impl Name {
} }
impl fmt::Debug for Name { impl fmt::Debug for Name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.host, f) fmt::Debug::fmt(&self.host, f)
} }
} }
impl fmt::Display for Name { impl fmt::Display for Name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.host, f) fmt::Display::fmt(&self.host, f)
} }
} }
@@ -100,7 +100,7 @@ impl FromStr for Name {
pub struct InvalidNameError(()); pub struct InvalidNameError(());
impl fmt::Display for InvalidNameError { impl fmt::Display for InvalidNameError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Not a valid domain name") f.write_str("Not a valid domain name")
} }
} }
@@ -166,7 +166,7 @@ impl Resolve for GaiResolver {
} }
impl fmt::Debug for GaiResolver { impl fmt::Debug for GaiResolver {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("GaiResolver") f.pad("GaiResolver")
} }
} }
@@ -184,7 +184,7 @@ impl Future for GaiFuture {
} }
impl fmt::Debug for GaiFuture { impl fmt::Debug for GaiFuture {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("GaiFuture") f.pad("GaiFuture")
} }
} }
@@ -198,7 +198,7 @@ impl Iterator for GaiAddrs {
} }
impl fmt::Debug for GaiAddrs { impl fmt::Debug for GaiAddrs {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("GaiAddrs") f.pad("GaiAddrs")
} }
} }

View File

@@ -198,7 +198,7 @@ impl<R> HttpConnector<R> {
// R: Debug required for now to allow adding it to debug output later... // R: Debug required for now to allow adding it to debug output later...
impl<R: fmt::Debug> fmt::Debug for HttpConnector<R> { impl<R: fmt::Debug> fmt::Debug for HttpConnector<R> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("HttpConnector") f.debug_struct("HttpConnector")
.finish() .finish()
} }
@@ -282,7 +282,7 @@ enum InvalidUrl {
} }
impl fmt::Display for InvalidUrl { impl fmt::Display for InvalidUrl {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.description()) f.write_str(self.description())
} }
} }
@@ -382,7 +382,7 @@ where
} }
impl<R: Resolve + fmt::Debug> fmt::Debug for HttpConnecting<R> { impl<R: Resolve + fmt::Debug> fmt::Debug for HttpConnecting<R> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("HttpConnecting") f.pad("HttpConnecting")
} }
} }
@@ -615,8 +615,6 @@ mod tests {
#[test] #[test]
#[cfg_attr(not(feature = "__internal_happy_eyeballs_tests"), ignore)] #[cfg_attr(not(feature = "__internal_happy_eyeballs_tests"), ignore)]
fn client_happy_eyeballs() { fn client_happy_eyeballs() {
extern crate pretty_env_logger;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, TcpListener}; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, TcpListener};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};

View File

@@ -346,7 +346,7 @@ impl Clone for Extra {
} }
impl fmt::Debug for Extra { impl fmt::Debug for Extra {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Extra") f.debug_struct("Extra")
.finish() .finish()
} }

View File

@@ -1,7 +1,6 @@
use futures_core::Stream; use futures_core::Stream;
use futures_channel::{mpsc, oneshot}; use futures_channel::{mpsc, oneshot};
use futures_util::future; use futures_util::future;
use want;
use crate::common::{Future, Never, Pin, Poll, task}; use crate::common::{Future, Never, Pin, Poll, task};
@@ -254,7 +253,6 @@ mod tests {
// trigger a warning to remind us // trigger a warning to remind us
use crate::Error; use crate::Error;
/* /*
extern crate pretty_env_logger;
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
extern crate test; extern crate test;

View File

@@ -137,7 +137,6 @@ impl Client<(), Body> {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # extern crate hyper;
/// # #[cfg(feature = "runtime")] /// # #[cfg(feature = "runtime")]
/// # fn run () { /// # fn run () {
/// use hyper::Client; /// use hyper::Client;
@@ -175,7 +174,6 @@ where C: Connect + Sync + 'static,
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # extern crate hyper;
/// # #[cfg(feature = "runtime")] /// # #[cfg(feature = "runtime")]
/// # fn run () { /// # fn run () {
/// use hyper::{Client, Uri}; /// use hyper::{Client, Uri};
@@ -205,7 +203,6 @@ where C: Connect + Sync + 'static,
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # extern crate hyper;
/// # #[cfg(feature = "runtime")] /// # #[cfg(feature = "runtime")]
/// # fn run () { /// # fn run () {
/// use hyper::{Body, Client, Request}; /// use hyper::{Body, Client, Request};
@@ -558,7 +555,7 @@ impl<C, B> Clone for Client<C, B> {
} }
impl<C, B> fmt::Debug for Client<C, B> { impl<C, B> fmt::Debug for Client<C, B> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Client") f.debug_struct("Client")
.finish() .finish()
} }
@@ -580,7 +577,7 @@ impl ResponseFuture {
} }
impl fmt::Debug for ResponseFuture { impl fmt::Debug for ResponseFuture {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("Future<Response>") f.pad("Future<Response>")
} }
} }
@@ -821,7 +818,6 @@ fn set_scheme(uri: &mut Uri, scheme: Scheme) {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # extern crate hyper;
/// # #[cfg(feature = "runtime")] /// # #[cfg(feature = "runtime")]
/// # fn run () { /// # fn run () {
/// use hyper::Client; /// use hyper::Client;
@@ -1053,7 +1049,7 @@ impl Builder {
} }
impl fmt::Debug for Builder { impl fmt::Debug for Builder {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Builder") f.debug_struct("Builder")
.field("client_config", &self.client_config) .field("client_config", &self.client_config)
.field("conn_builder", &self.conn_builder) .field("conn_builder", &self.conn_builder)
@@ -1097,7 +1093,6 @@ mod unit_tests {
#[test] #[test]
fn test_authority_form() { fn test_authority_form() {
extern crate pretty_env_logger;
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let mut uri = "http://hyper.rs".parse().unwrap(); let mut uri = "http://hyper.rs".parse().unwrap();

View File

@@ -171,7 +171,7 @@ impl<T: Poolable> Pool<T> {
} }
#[cfg(test)] #[cfg(test)]
fn locked(&self) -> ::std::sync::MutexGuard<PoolInner<T>> { fn locked(&self) -> ::std::sync::MutexGuard<'_, PoolInner<T>> {
self self
.inner .inner
.as_ref() .as_ref()
@@ -263,7 +263,7 @@ impl<T: Poolable> Pool<T> {
} }
/// Pop off this list, looking for a usable connection that hasn't expired. /// Pop off this list, looking for a usable connection that hasn't expired.
struct IdlePopper<'a, T: 'a> { struct IdlePopper<'a, T> {
key: &'a Key, key: &'a Key,
list: &'a mut Vec<Idle<T>>, list: &'a mut Vec<Idle<T>>,
} }
@@ -547,7 +547,7 @@ impl<T: Poolable> Drop for Pooled<T> {
} }
impl<T: Poolable> fmt::Debug for Pooled<T> { impl<T: Poolable> fmt::Debug for Pooled<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Pooled") f.debug_struct("Pooled")
.field("key", &self.key) .field("key", &self.key)
.finish() .finish()

View File

@@ -3,7 +3,6 @@
use super::Client; use super::Client;
/* /*
#![cfg(feature = "runtime")] #![cfg(feature = "runtime")]
extern crate pretty_env_logger;
use futures::{Async, Future, Stream}; use futures::{Async, Future, Stream};
use futures::future::poll_fn; use futures::future::poll_fn;

View File

@@ -57,13 +57,13 @@ impl Exec {
struct TokioSpawnError; struct TokioSpawnError;
impl fmt::Debug for TokioSpawnError { impl fmt::Debug for TokioSpawnError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt("tokio::spawn failed (is a tokio runtime running this future?)", f) fmt::Debug::fmt("tokio::spawn failed (is a tokio runtime running this future?)", f)
} }
} }
impl fmt::Display for TokioSpawnError { impl fmt::Display for TokioSpawnError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt("tokio::spawn failed (is a tokio runtime running this future?)", f) fmt::Display::fmt("tokio::spawn failed (is a tokio runtime running this future?)", f)
} }
} }
@@ -99,7 +99,7 @@ impl Exec {
} }
impl fmt::Debug for Exec { impl fmt::Debug for Exec {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Exec") f.debug_struct("Exec")
.finish() .finish()
} }

View File

@@ -129,8 +129,7 @@ mod tests {
use super::Rewind; use super::Rewind;
/* /*
use super::*; use super::*;
extern crate tokio_mockstream; use tokio_mockstream::MockStream;
use self::tokio_mockstream::MockStream;
use std::io::Cursor; use std::io::Cursor;
// Test a partial rewind // Test a partial rewind

View File

@@ -9,7 +9,7 @@ use std::fmt;
pub enum Never {} pub enum Never {}
impl fmt::Display for Never { impl fmt::Display for Never {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {} match *self {}
} }
} }

View File

@@ -4,7 +4,7 @@ use super::Never;
/// A function to help "yield" a future, such that it is re-scheduled immediately. /// A function to help "yield" a future, such that it is re-scheduled immediately.
/// ///
/// Useful for spin counts, so a future doesn't hog too much time. /// Useful for spin counts, so a future doesn't hog too much time.
pub(crate) fn yield_now(cx: &mut Context) -> Poll<Never> { pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll<Never> {
cx.waker().wake_by_ref(); cx.waker().wake_by_ref();
Poll::Pending Poll::Pending
} }

View File

@@ -3,10 +3,6 @@ use std::error::Error as StdError;
use std::fmt; use std::fmt;
use std::io; use std::io;
use httparse;
use http;
use h2;
/// Result type often returned from methods that can have hyper `Error`s. /// Result type often returned from methods that can have hyper `Error`s.
pub type Result<T> = ::std::result::Result<T, Error>; pub type Result<T> = ::std::result::Result<T, Error>;
@@ -284,7 +280,7 @@ impl Error {
} }
impl fmt::Debug for Error { impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut f = f.debug_tuple("Error"); let mut f = f.debug_tuple("Error");
f.field(&self.inner.kind); f.field(&self.inner.kind);
if let Some(ref cause) = self.inner.cause { if let Some(ref cause) = self.inner.cause {
@@ -295,7 +291,7 @@ impl fmt::Debug for Error {
} }
impl fmt::Display for Error { impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(ref cause) = self.inner.cause { if let Some(ref cause) = self.inner.cause {
write!(f, "{}: {}", self.description(), cause) write!(f, "{}: {}", self.description(), cause)
} else { } else {

View File

@@ -33,7 +33,7 @@ pub fn content_length_parse_all(headers: &HeaderMap) -> Option<u64> {
content_length_parse_all_values(headers.get_all(CONTENT_LENGTH).into_iter()) content_length_parse_all_values(headers.get_all(CONTENT_LENGTH).into_iter())
} }
pub fn content_length_parse_all_values(values: ValueIter<HeaderValue>) -> Option<u64> { pub fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>) -> Option<u64> {
// If multiple Content-Length headers were sent, everything can still // If multiple Content-Length headers were sent, everything can still
// be alright if they all contain the same value, and all parse // be alright if they all contain the same value, and all parse
// correctly. If not, then it's an error. // correctly. If not, then it's an error.
@@ -74,7 +74,7 @@ pub fn transfer_encoding_is_chunked(headers: &HeaderMap) -> bool {
is_chunked(headers.get_all(TRANSFER_ENCODING).into_iter()) is_chunked(headers.get_all(TRANSFER_ENCODING).into_iter())
} }
pub fn is_chunked(mut encodings: ValueIter<HeaderValue>) -> bool { pub fn is_chunked(mut encodings: ValueIter<'_, HeaderValue>) -> bool {
// chunked must always be the last encoding, according to spec // chunked must always be the last encoding, according to spec
if let Some(line) = encodings.next_back() { if let Some(line) = encodings.next_back() {
return is_chunked_(line); return is_chunked_(line);
@@ -94,7 +94,7 @@ pub fn is_chunked_(value: &HeaderValue) -> bool {
false false
} }
pub fn add_chunked(mut entry: OccupiedEntry<HeaderValue>) { pub fn add_chunked(mut entry: OccupiedEntry<'_, HeaderValue>) {
const CHUNKED: &'static str = "chunked"; const CHUNKED: &'static str = "chunked";
if let Some(line) = entry.iter_mut().next_back() { if let Some(line) = entry.iter_mut().next_back() {

View File

@@ -1,6 +1,7 @@
#![doc(html_root_url = "https://docs.rs/hyper/0.12.32")] #![doc(html_root_url = "https://docs.rs/hyper/0.12.32")]
#![deny(missing_docs)] #![deny(missing_docs)]
#![deny(missing_debug_implementations)] #![deny(missing_debug_implementations)]
#![deny(rust_2018_idioms)]
// XXX NOOOOOOOO // XXX NOOOOOOOO
//#![cfg_attr(test, deny(warnings))] //#![cfg_attr(test, deny(warnings))]
#![allow(warnings)] #![allow(warnings)]
@@ -19,7 +20,7 @@
//! If looking for just a convenient HTTP client, consider the //! If looking for just a convenient HTTP client, consider the
//! [reqwest](https://crates.io/crates/reqwest) crate. //! [reqwest](https://crates.io/crates/reqwest) crate.
#[doc(hidden)] pub extern crate http; #[doc(hidden)] pub use http;
#[macro_use] extern crate log; #[macro_use] extern crate log;
#[cfg(all(test, feature = "nightly"))] #[cfg(all(test, feature = "nightly"))]

View File

@@ -646,7 +646,7 @@ where I: AsyncRead + AsyncWrite + Unpin,
} }
impl<I, B: Buf, T> fmt::Debug for Conn<I, B, T> { impl<I, B: Buf, T> fmt::Debug for Conn<I, B, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Conn") f.debug_struct("Conn")
.field("state", &self.state) .field("state", &self.state)
.field("io", &self.io) .field("io", &self.io)
@@ -701,7 +701,7 @@ enum Writing {
} }
impl fmt::Debug for State { impl fmt::Debug for State {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut builder = f.debug_struct("State"); let mut builder = f.debug_struct("State");
builder builder
.field("reading", &self.reading) .field("reading", &self.reading)
@@ -720,7 +720,7 @@ impl fmt::Debug for State {
} }
impl fmt::Debug for Writing { impl fmt::Debug for Writing {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self { match *self {
Writing::Init => f.write_str("Init"), Writing::Init => f.write_str("Init"),
Writing::Body(ref enc) => f.debug_tuple("Body") Writing::Body(ref enc) => f.debug_tuple("Body")
@@ -1112,7 +1112,6 @@ mod tests {
#[test] #[test]
fn test_conn_body_write_length() { fn test_conn_body_write_length() {
extern crate pretty_env_logger;
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let _: Result<(), ()> = future::lazy(|| { let _: Result<(), ()> = future::lazy(|| {
let io = AsyncIo::new_buf(vec![], 0); let io = AsyncIo::new_buf(vec![], 0);

View File

@@ -147,7 +147,7 @@ impl Decoder {
impl fmt::Debug for Decoder { impl fmt::Debug for Decoder {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.kind, f) fmt::Debug::fmt(&self.kind, f)
} }
} }
@@ -306,7 +306,7 @@ impl ChunkedState {
struct IncompleteBody; struct IncompleteBody;
impl fmt::Display for IncompleteBody { impl fmt::Display for IncompleteBody {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.description()) f.write_str(self.description())
} }
} }

View File

@@ -602,8 +602,6 @@ mod tests {
// trigger a warning to remind us // trigger a warning to remind us
use crate::Error; use crate::Error;
/* /*
extern crate pretty_env_logger;
use super::*; use super::*;
use crate::mock::AsyncIo; use crate::mock::AsyncIo;
use crate::proto::h1::ClientTransaction; use crate::proto::h1::ClientTransaction;

View File

@@ -298,7 +298,7 @@ impl Buf for ChunkSize {
} }
impl fmt::Debug for ChunkSize { impl fmt::Debug for ChunkSize {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ChunkSize") f.debug_struct("ChunkSize")
.field("bytes", &&self.bytes[..self.len.into()]) .field("bytes", &&self.bytes[..self.len.into()])
.field("pos", &self.pos) .field("pos", &self.pos)

View File

@@ -42,7 +42,7 @@ impl<T, B> fmt::Debug for Buffered<T, B>
where where
B: Buf, B: Buf,
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Buffered") f.debug_struct("Buffered")
.field("read_buf", &self.read_buf) .field("read_buf", &self.read_buf)
.field("write_buf", &self.write_buf) .field("write_buf", &self.write_buf)
@@ -135,7 +135,7 @@ where
} }
} }
pub(super) fn parse<S>(&mut self, cx: &mut task::Context<'_>, parse_ctx: ParseContext) pub(super) fn parse<S>(&mut self, cx: &mut task::Context<'_>, parse_ctx: ParseContext<'_>)
-> Poll<crate::Result<ParsedMessage<S::Incoming>>> -> Poll<crate::Result<ParsedMessage<S::Incoming>>>
where where
S: Http1Transaction, S: Http1Transaction,
@@ -376,7 +376,7 @@ impl Cursor<Vec<u8>> {
} }
impl<T: AsRef<[u8]>> fmt::Debug for Cursor<T> { impl<T: AsRef<[u8]>> fmt::Debug for Cursor<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Cursor") f.debug_struct("Cursor")
.field("pos", &self.pos) .field("pos", &self.pos)
.field("len", &self.bytes.as_ref().len()) .field("len", &self.bytes.as_ref().len())
@@ -433,7 +433,7 @@ where
} }
#[inline] #[inline]
fn auto(&mut self) -> WriteBufAuto<B> { fn auto(&mut self) -> WriteBufAuto<'_, B> {
WriteBufAuto::new(self) WriteBufAuto::new(self)
} }
@@ -481,7 +481,7 @@ where
} }
impl<B: Buf> fmt::Debug for WriteBuf<B> { impl<B: Buf> fmt::Debug for WriteBuf<B> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("WriteBuf") f.debug_struct("WriteBuf")
.field("remaining", &self.remaining()) .field("remaining", &self.remaining())
.field("strategy", &self.strategy) .field("strategy", &self.strategy)
@@ -528,7 +528,7 @@ impl<B: Buf> Buf for WriteBuf<B> {
/// Detects when wrapped `WriteBuf` is used for vectored IO, and /// Detects when wrapped `WriteBuf` is used for vectored IO, and
/// adjusts the `WriteBuf` strategy if not. /// adjusts the `WriteBuf` strategy if not.
struct WriteBufAuto<'a, B: Buf + 'a> { struct WriteBufAuto<'a, B: Buf> {
bytes_called: Cell<bool>, bytes_called: Cell<bool>,
bytes_vec_called: Cell<bool>, bytes_vec_called: Cell<bool>,
inner: &'a mut WriteBuf<B>, inner: &'a mut WriteBuf<B>,
@@ -822,7 +822,6 @@ mod tests {
TODO: needs tokio_test::io to allow configure write_buf calls TODO: needs tokio_test::io to allow configure write_buf calls
#[test] #[test]
fn write_buf_queue() { fn write_buf_queue() {
extern crate pretty_env_logger;
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let mock = AsyncIo::new_buf(vec![], 1024); let mock = AsyncIo::new_buf(vec![], 1024);
@@ -844,7 +843,6 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn write_buf_flatten() { async fn write_buf_flatten() {
extern crate pretty_env_logger;
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let mock = Mock::new() let mock = Mock::new()
@@ -866,7 +864,6 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn write_buf_auto_flatten() { async fn write_buf_auto_flatten() {
extern crate pretty_env_logger;
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let mock = Mock::new() let mock = Mock::new()
@@ -894,7 +891,6 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn write_buf_queue_disable_auto() { async fn write_buf_queue_disable_auto() {
extern crate pretty_env_logger;
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let mock = Mock::new() let mock = Mock::new()

View File

@@ -26,8 +26,8 @@ pub(crate) trait Http1Transaction {
type Incoming; type Incoming;
type Outgoing: Default; type Outgoing: Default;
const LOG: &'static str; const LOG: &'static str;
fn parse(bytes: &mut BytesMut, ctx: ParseContext) -> ParseResult<Self::Incoming>; fn parse(bytes: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult<Self::Incoming>;
fn encode(enc: Encode<Self::Outgoing>, dst: &mut Vec<u8>) -> crate::Result<Encoder>; fn encode(enc: Encode<'_, Self::Outgoing>, dst: &mut Vec<u8>) -> crate::Result<Encoder>;
fn on_error(err: &crate::Error) -> Option<MessageHead<Self::Outgoing>>; fn on_error(err: &crate::Error) -> Option<MessageHead<Self::Outgoing>>;
@@ -68,7 +68,7 @@ pub(crate) struct ParseContext<'a> {
} }
/// Passed to Http1Transaction::encode /// Passed to Http1Transaction::encode
pub(crate) struct Encode<'a, T: 'a> { pub(crate) struct Encode<'a, T> {
head: &'a mut MessageHead<T>, head: &'a mut MessageHead<T>,
body: Option<BodyLength>, body: Option<BodyLength>,
keep_alive: bool, keep_alive: bool,

View File

@@ -8,7 +8,6 @@ use std::mem;
use bytes::{BytesMut}; use bytes::{BytesMut};
use http::header::{self, Entry, HeaderName, HeaderValue}; use http::header::{self, Entry, HeaderName, HeaderValue};
use http::{HeaderMap, Method, StatusCode, Version}; use http::{HeaderMap, Method, StatusCode, Version};
use httparse;
use crate::error::Parse; use crate::error::Parse;
use crate::headers; use crate::headers;
@@ -68,7 +67,7 @@ impl Http1Transaction for Server {
type Outgoing = StatusCode; type Outgoing = StatusCode;
const LOG: &'static str = "{role=server}"; const LOG: &'static str = "{role=server}";
fn parse(buf: &mut BytesMut, ctx: ParseContext) -> ParseResult<RequestLine> { fn parse(buf: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult<RequestLine> {
if buf.is_empty() { if buf.is_empty() {
return Ok(None); return Ok(None);
} }
@@ -86,7 +85,7 @@ impl Http1Transaction for Server {
// a good ~5% on pipeline benchmarks. // a good ~5% on pipeline benchmarks.
let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() }; let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() };
{ {
let mut headers: [httparse::Header; MAX_HEADERS] = unsafe { mem::uninitialized() }; let mut headers: [httparse::Header<'_>; MAX_HEADERS] = unsafe { mem::uninitialized() };
trace!("Request.parse([Header; {}], [u8; {}])", headers.len(), buf.len()); trace!("Request.parse([Header; {}], [u8; {}])", headers.len(), buf.len());
let mut req = httparse::Request::new(&mut headers); let mut req = httparse::Request::new(&mut headers);
let bytes = buf.as_ref(); let bytes = buf.as_ref();
@@ -239,7 +238,7 @@ impl Http1Transaction for Server {
})) }))
} }
fn encode(mut msg: Encode<Self::Outgoing>, mut dst: &mut Vec<u8>) -> crate::Result<Encoder> { fn encode(mut msg: Encode<'_, Self::Outgoing>, mut dst: &mut Vec<u8>) -> crate::Result<Encoder> {
trace!( trace!(
"Server::encode status={:?}, body={:?}, req_method={:?}", "Server::encode status={:?}, body={:?}, req_method={:?}",
msg.head.subject, msg.head.subject,
@@ -589,7 +588,7 @@ impl Http1Transaction for Client {
type Outgoing = RequestLine; type Outgoing = RequestLine;
const LOG: &'static str = "{role=client}"; const LOG: &'static str = "{role=client}";
fn parse(buf: &mut BytesMut, ctx: ParseContext) -> ParseResult<StatusCode> { fn parse(buf: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult<StatusCode> {
// Loop to skip information status code headers (100 Continue, etc). // Loop to skip information status code headers (100 Continue, etc).
loop { loop {
if buf.is_empty() { if buf.is_empty() {
@@ -598,7 +597,7 @@ impl Http1Transaction for Client {
// Unsafe: see comment in Server Http1Transaction, above. // Unsafe: see comment in Server Http1Transaction, above.
let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() }; let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() };
let (len, status, version, headers_len) = { let (len, status, version, headers_len) = {
let mut headers: [httparse::Header; MAX_HEADERS] = unsafe { mem::uninitialized() }; let mut headers: [httparse::Header<'_>; MAX_HEADERS] = unsafe { mem::uninitialized() };
trace!("Response.parse([Header; {}], [u8; {}])", headers.len(), buf.len()); trace!("Response.parse([Header; {}], [u8; {}])", headers.len(), buf.len());
let mut res = httparse::Response::new(&mut headers); let mut res = httparse::Response::new(&mut headers);
let bytes = buf.as_ref(); let bytes = buf.as_ref();
@@ -666,7 +665,7 @@ impl Http1Transaction for Client {
} }
} }
fn encode(msg: Encode<Self::Outgoing>, dst: &mut Vec<u8>) -> crate::Result<Encoder> { fn encode(msg: Encode<'_, Self::Outgoing>, dst: &mut Vec<u8>) -> crate::Result<Encoder> {
trace!("Client::encode method={:?}, body={:?}", msg.head.subject.0, msg.body); trace!("Client::encode method={:?}, body={:?}", msg.head.subject.0, msg.body);
*msg.req_method = Some(msg.head.subject.0.clone()); *msg.req_method = Some(msg.head.subject.0.clone());
@@ -935,7 +934,7 @@ struct HeaderIndices {
fn record_header_indices( fn record_header_indices(
bytes: &[u8], bytes: &[u8],
headers: &[httparse::Header], headers: &[httparse::Header<'_>],
indices: &mut [HeaderIndices] indices: &mut [HeaderIndices]
) -> Result<(), crate::error::Parse> { ) -> Result<(), crate::error::Parse> {
let bytes_ptr = bytes.as_ptr() as usize; let bytes_ptr = bytes.as_ptr() as usize;
@@ -1044,7 +1043,7 @@ impl<'a> fmt::Write for FastWrite<'a> {
} }
#[inline] #[inline]
fn write_fmt(&mut self, args: fmt::Arguments) -> fmt::Result { fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> fmt::Result {
fmt::write(self, args) fmt::write(self, args)
} }
} }
@@ -1062,7 +1061,6 @@ mod tests {
#[test] #[test]
fn test_parse_request() { fn test_parse_request() {
extern crate pretty_env_logger;
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let mut raw = BytesMut::from(b"GET /echo HTTP/1.1\r\nHost: hyper.rs\r\n\r\n".to_vec()); let mut raw = BytesMut::from(b"GET /echo HTTP/1.1\r\nHost: hyper.rs\r\n\r\n".to_vec());
let mut method = None; let mut method = None;
@@ -1082,7 +1080,6 @@ mod tests {
#[test] #[test]
fn test_parse_response() { fn test_parse_response() {
extern crate pretty_env_logger;
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let mut raw = BytesMut::from(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n".to_vec()); let mut raw = BytesMut::from(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n".to_vec());
let ctx = ParseContext { let ctx = ParseContext {

View File

@@ -94,7 +94,7 @@ mod body_length {
} }
impl fmt::Display for DecodedLength { impl fmt::Display for DecodedLength {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self { match *self {
DecodedLength::CLOSE_DELIMITED => f.write_str("close-delimited"), DecodedLength::CLOSE_DELIMITED => f.write_str("close-delimited"),
DecodedLength::CHUNKED => f.write_str("chunked encoding"), DecodedLength::CHUNKED => f.write_str("chunked encoding"),

View File

@@ -17,7 +17,6 @@ use std::sync::Arc;
use bytes::Bytes; use bytes::Bytes;
use futures_core::Stream; use futures_core::Stream;
use h2;
use pin_utils::{unsafe_pinned, unsafe_unpinned}; use pin_utils::{unsafe_pinned, unsafe_unpinned};
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
#[cfg(feature = "runtime")] use tokio_net::driver::Handle; #[cfg(feature = "runtime")] use tokio_net::driver::Handle;
@@ -666,7 +665,7 @@ impl<I, S> fmt::Debug for Connection<I, S>
where where
S: Service<Body>, S: Service<Body>,
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Connection") f.debug_struct("Connection")
.finish() .finish()
} }

View File

@@ -222,7 +222,7 @@ where
} }
impl<I: fmt::Debug, S: fmt::Debug> fmt::Debug for Server<I, S> { impl<I: fmt::Debug, S: fmt::Debug> fmt::Debug for Server<I, S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Server") f.debug_struct("Server")
.field("listener", &self.spawn_all.incoming_ref()) .field("listener", &self.spawn_all.incoming_ref())
.finish() .finish()

View File

@@ -182,7 +182,7 @@ fn is_connection_error(e: &io::Error) -> bool {
} }
impl fmt::Debug for AddrIncoming { impl fmt::Debug for AddrIncoming {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("AddrIncoming") f.debug_struct("AddrIncoming")
.field("addr", &self.addr) .field("addr", &self.addr)
.field("sleep_on_errors", &self.sleep_on_errors) .field("sleep_on_errors", &self.sleep_on_errors)

View File

@@ -201,7 +201,7 @@ where
} }
impl<F> fmt::Debug for MakeServiceFn<F> { impl<F> fmt::Debug for MakeServiceFn<F> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("MakeServiceFn") f.debug_struct("MakeServiceFn")
.finish() .finish()
} }

View File

@@ -122,7 +122,7 @@ where
} }
impl<F, R> fmt::Debug for ServiceFn<F, R> { impl<F, R> fmt::Debug for ServiceFn<F, R> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("impl Service") f.debug_struct("impl Service")
.finish() .finish()
} }

View File

@@ -160,7 +160,7 @@ impl AsyncWrite for Upgraded {
} }
impl fmt::Debug for Upgraded { impl fmt::Debug for Upgraded {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Upgraded") f.debug_struct("Upgraded")
.finish() .finish()
} }
@@ -198,7 +198,7 @@ impl Future for OnUpgrade {
} }
impl fmt::Debug for OnUpgrade { impl fmt::Debug for OnUpgrade {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OnUpgrade") f.debug_struct("OnUpgrade")
.finish() .finish()
} }
@@ -223,7 +223,7 @@ impl Pending {
// ===== impl UpgradeExpected ===== // ===== impl UpgradeExpected =====
impl fmt::Display for UpgradeExpected { impl fmt::Display for UpgradeExpected {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.description()) f.write_str(self.description())
} }
} }

View File

@@ -1,13 +1,7 @@
#![deny(warnings)] #![deny(warnings)]
extern crate bytes; #![warn(rust_2018_idioms)]
extern crate hyper;
#[macro_use] extern crate matches; #[macro_use] extern crate matches;
extern crate net2;
extern crate pretty_env_logger;
extern crate tokio;
extern crate tokio_io;
extern crate tokio_net;
extern crate tokio_timer;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::net::{SocketAddr, TcpListener}; use std::net::{SocketAddr, TcpListener};
@@ -777,9 +771,6 @@ mod dispatch_impl {
use hyper::client::connect::{Connect, Connected, Destination, HttpConnector}; use hyper::client::connect::{Connect, Connected, Destination, HttpConnector};
use hyper::Client; use hyper::Client;
use hyper;
#[test] #[test]
fn drop_body_before_eof_closes_connection() { fn drop_body_before_eof_closes_connection() {
@@ -1609,7 +1600,7 @@ mod dispatch_impl {
impl AsyncRead for DebugStream { impl AsyncRead for DebugStream {
fn poll_read( fn poll_read(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
cx: &mut Context, cx: &mut Context<'_>,
buf: &mut [u8], buf: &mut [u8],
) -> Poll<Result<usize, io::Error>> { ) -> Poll<Result<usize, io::Error>> {
Pin::new(&mut self.0).poll_read(cx, buf) Pin::new(&mut self.0).poll_read(cx, buf)
@@ -2171,7 +2162,7 @@ mod conn {
impl AsyncRead for DebugStream { impl AsyncRead for DebugStream {
fn poll_read( fn poll_read(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
cx: &mut Context, cx: &mut Context<'_>,
buf: &mut [u8], buf: &mut [u8],
) -> Poll<Result<usize, io::Error>> { ) -> Poll<Result<usize, io::Error>> {
Pin::new(&mut self.tcp).poll_read(cx, buf) Pin::new(&mut self.tcp).poll_read(cx, buf)

View File

@@ -1,14 +1,6 @@
#![feature(async_closure)] #![feature(async_closure)]
#![deny(warnings)] #![deny(warnings)]
extern crate http; #![warn(rust_2018_idioms)]
extern crate hyper;
extern crate h2;
extern crate net2;
extern crate spmc;
extern crate pretty_env_logger;
extern crate tokio;
extern crate tokio_io;
extern crate tokio_net;
use std::net::{TcpStream, Shutdown, SocketAddr}; use std::net::{TcpStream, Shutdown, SocketAddr};
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
@@ -1241,7 +1233,7 @@ fn http_connect() {
#[test] #[test]
fn upgrades_new() { fn upgrades_new() {
use crate::tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::io::{AsyncReadExt, AsyncWriteExt};
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let mut rt = Runtime::new().unwrap(); let mut rt = Runtime::new().unwrap();
@@ -1765,7 +1757,7 @@ impl Serve {
Ok(buf) Ok(buf)
} }
fn reply(&self) -> ReplyBuilder { fn reply(&self) -> ReplyBuilder<'_> {
ReplyBuilder { ReplyBuilder {
tx: &self.reply_tx tx: &self.reply_tx
} }

View File

@@ -1,21 +1,17 @@
pub extern crate hyper;
pub extern crate tokio;
extern crate futures_util;
use std::future::Future; use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::sync::{Arc, Mutex, atomic::{AtomicUsize, Ordering}}; use std::sync::{Arc, Mutex, atomic::{AtomicUsize, Ordering}};
use std::time::{Duration/*, Instant*/}; use std::time::{Duration/*, Instant*/};
use crate::hyper::{Body, Client, Request, Response, Server, Version}; use hyper::{Body, Client, Request, Response, Server, Version};
use crate::hyper::client::HttpConnector; use hyper::client::HttpConnector;
use crate::hyper::service::{make_service_fn, service_fn}; use hyper::service::{make_service_fn, service_fn};
pub use std::net::SocketAddr; pub use std::net::SocketAddr;
pub use self::futures_util::{future, try_future, FutureExt as _, StreamExt as _, TryFutureExt as _, TryStreamExt as _}; pub use futures_util::{future, try_future, FutureExt as _, StreamExt as _, TryFutureExt as _, TryStreamExt as _};
//pub use self::futures_channel::oneshot; //pub use self::futures_channel::oneshot;
pub use self::hyper::{HeaderMap, StatusCode}; pub use hyper::{HeaderMap, StatusCode};
pub use self::tokio::runtime::current_thread::Runtime; pub use tokio::runtime::current_thread::Runtime;
macro_rules! t { macro_rules! t {
( (
@@ -209,12 +205,12 @@ macro_rules! __internal_headers_map {
macro_rules! __internal_headers_eq { macro_rules! __internal_headers_eq {
(@pat $name: expr, $pat:pat) => { (@pat $name: expr, $pat:pat) => {
::std::sync::Arc::new(move |__hdrs: &crate::hyper::HeaderMap| { ::std::sync::Arc::new(move |__hdrs: &hyper::HeaderMap| {
match __hdrs.get($name) { match __hdrs.get($name) {
$pat => (), $pat => (),
other => panic!("headers[{}] was not {}: {:?}", stringify!($name), stringify!($pat), other), other => panic!("headers[{}] was not {}: {:?}", stringify!($name), stringify!($pat), other),
} }
}) as ::std::sync::Arc<dyn Fn(&crate::hyper::HeaderMap) + Send + Sync> }) as ::std::sync::Arc<dyn Fn(&hyper::HeaderMap) + Send + Sync>
}; };
(@val $name: expr, NONE) => { (@val $name: expr, NONE) => {
__internal_headers_eq!(@pat $name, None); __internal_headers_eq!(@pat $name, None);
@@ -224,13 +220,13 @@ macro_rules! __internal_headers_eq {
}; };
(@val $name: expr, $val:expr) => ({ (@val $name: expr, $val:expr) => ({
let __val = Option::from($val); let __val = Option::from($val);
::std::sync::Arc::new(move |__hdrs: &crate::hyper::HeaderMap| { ::std::sync::Arc::new(move |__hdrs: &hyper::HeaderMap| {
if let Some(ref val) = __val { if let Some(ref val) = __val {
assert_eq!(__hdrs.get($name).expect(stringify!($name)), val.to_string().as_str(), stringify!($name)); assert_eq!(__hdrs.get($name).expect(stringify!($name)), val.to_string().as_str(), stringify!($name));
} else { } else {
assert_eq!(__hdrs.get($name), None, stringify!($name)); assert_eq!(__hdrs.get($name), None, stringify!($name));
} }
}) as ::std::sync::Arc<dyn Fn(&crate::hyper::HeaderMap) + Send + Sync> }) as ::std::sync::Arc<dyn Fn(&hyper::HeaderMap) + Send + Sync>
}); });
($headers:ident, { $($name:expr => $val:tt,)* }) => { ($headers:ident, { $($name:expr => $val:tt,)* }) => {
$( $(
@@ -306,7 +302,6 @@ pub struct __TestConfig {
} }
pub fn __run_test(cfg: __TestConfig) { pub fn __run_test(cfg: __TestConfig) {
extern crate pretty_env_logger;
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let mut rt = Runtime::new().expect("new rt"); let mut rt = Runtime::new().expect("new rt");
@@ -379,7 +374,7 @@ pub fn __run_test(cfg: __TestConfig) {
let fut = connecting let fut = connecting
.then(|res| res.expect("connecting")) .then(|res| res.expect("connecting"))
.map(|conn_res| conn_res.expect("server connection error")); .map(|conn_res| conn_res.expect("server connection error"));
crate::tokio::spawn(fut); tokio::spawn(fut);
future::ok::<_, hyper::Error>(cnt) future::ok::<_, hyper::Error>(cnt)
}) })
.map(|res| { .map(|res| {