style(lib): use rust 2018 edition idioms (#1910)
This commit is contained in:
@@ -646,7 +646,7 @@ where I: AsyncRead + AsyncWrite + Unpin,
|
||||
}
|
||||
|
||||
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")
|
||||
.field("state", &self.state)
|
||||
.field("io", &self.io)
|
||||
@@ -701,7 +701,7 @@ enum Writing {
|
||||
}
|
||||
|
||||
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");
|
||||
builder
|
||||
.field("reading", &self.reading)
|
||||
@@ -720,7 +720,7 @@ impl fmt::Debug for State {
|
||||
}
|
||||
|
||||
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 {
|
||||
Writing::Init => f.write_str("Init"),
|
||||
Writing::Body(ref enc) => f.debug_tuple("Body")
|
||||
@@ -1112,7 +1112,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_conn_body_write_length() {
|
||||
extern crate pretty_env_logger;
|
||||
let _ = pretty_env_logger::try_init();
|
||||
let _: Result<(), ()> = future::lazy(|| {
|
||||
let io = AsyncIo::new_buf(vec![], 0);
|
||||
|
||||
@@ -147,7 +147,7 @@ impl 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)
|
||||
}
|
||||
}
|
||||
@@ -306,7 +306,7 @@ impl ChunkedState {
|
||||
struct 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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,8 +602,6 @@ mod tests {
|
||||
// trigger a warning to remind us
|
||||
use crate::Error;
|
||||
/*
|
||||
extern crate pretty_env_logger;
|
||||
|
||||
use super::*;
|
||||
use crate::mock::AsyncIo;
|
||||
use crate::proto::h1::ClientTransaction;
|
||||
|
||||
@@ -298,7 +298,7 @@ impl Buf 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")
|
||||
.field("bytes", &&self.bytes[..self.len.into()])
|
||||
.field("pos", &self.pos)
|
||||
|
||||
@@ -42,7 +42,7 @@ impl<T, B> fmt::Debug for Buffered<T, B>
|
||||
where
|
||||
B: Buf,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Buffered")
|
||||
.field("read_buf", &self.read_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>>>
|
||||
where
|
||||
S: Http1Transaction,
|
||||
@@ -376,7 +376,7 @@ impl Cursor<Vec<u8>> {
|
||||
}
|
||||
|
||||
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")
|
||||
.field("pos", &self.pos)
|
||||
.field("len", &self.bytes.as_ref().len())
|
||||
@@ -433,7 +433,7 @@ where
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn auto(&mut self) -> WriteBufAuto<B> {
|
||||
fn auto(&mut self) -> WriteBufAuto<'_, B> {
|
||||
WriteBufAuto::new(self)
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ where
|
||||
}
|
||||
|
||||
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")
|
||||
.field("remaining", &self.remaining())
|
||||
.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
|
||||
/// adjusts the `WriteBuf` strategy if not.
|
||||
struct WriteBufAuto<'a, B: Buf + 'a> {
|
||||
struct WriteBufAuto<'a, B: Buf> {
|
||||
bytes_called: Cell<bool>,
|
||||
bytes_vec_called: Cell<bool>,
|
||||
inner: &'a mut WriteBuf<B>,
|
||||
@@ -822,7 +822,6 @@ mod tests {
|
||||
TODO: needs tokio_test::io to allow configure write_buf calls
|
||||
#[test]
|
||||
fn write_buf_queue() {
|
||||
extern crate pretty_env_logger;
|
||||
let _ = pretty_env_logger::try_init();
|
||||
|
||||
let mock = AsyncIo::new_buf(vec![], 1024);
|
||||
@@ -844,7 +843,6 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn write_buf_flatten() {
|
||||
extern crate pretty_env_logger;
|
||||
let _ = pretty_env_logger::try_init();
|
||||
|
||||
let mock = Mock::new()
|
||||
@@ -866,7 +864,6 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn write_buf_auto_flatten() {
|
||||
extern crate pretty_env_logger;
|
||||
let _ = pretty_env_logger::try_init();
|
||||
|
||||
let mock = Mock::new()
|
||||
@@ -894,7 +891,6 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn write_buf_queue_disable_auto() {
|
||||
extern crate pretty_env_logger;
|
||||
let _ = pretty_env_logger::try_init();
|
||||
|
||||
let mock = Mock::new()
|
||||
|
||||
@@ -26,8 +26,8 @@ pub(crate) trait Http1Transaction {
|
||||
type Incoming;
|
||||
type Outgoing: Default;
|
||||
const LOG: &'static str;
|
||||
fn parse(bytes: &mut BytesMut, ctx: ParseContext) -> ParseResult<Self::Incoming>;
|
||||
fn encode(enc: Encode<Self::Outgoing>, dst: &mut Vec<u8>) -> crate::Result<Encoder>;
|
||||
fn parse(bytes: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult<Self::Incoming>;
|
||||
fn encode(enc: Encode<'_, Self::Outgoing>, dst: &mut Vec<u8>) -> crate::Result<Encoder>;
|
||||
|
||||
fn on_error(err: &crate::Error) -> Option<MessageHead<Self::Outgoing>>;
|
||||
|
||||
@@ -68,7 +68,7 @@ pub(crate) struct ParseContext<'a> {
|
||||
}
|
||||
|
||||
/// Passed to Http1Transaction::encode
|
||||
pub(crate) struct Encode<'a, T: 'a> {
|
||||
pub(crate) struct Encode<'a, T> {
|
||||
head: &'a mut MessageHead<T>,
|
||||
body: Option<BodyLength>,
|
||||
keep_alive: bool,
|
||||
|
||||
@@ -8,7 +8,6 @@ use std::mem;
|
||||
use bytes::{BytesMut};
|
||||
use http::header::{self, Entry, HeaderName, HeaderValue};
|
||||
use http::{HeaderMap, Method, StatusCode, Version};
|
||||
use httparse;
|
||||
|
||||
use crate::error::Parse;
|
||||
use crate::headers;
|
||||
@@ -68,7 +67,7 @@ impl Http1Transaction for Server {
|
||||
type Outgoing = StatusCode;
|
||||
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() {
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -86,7 +85,7 @@ impl Http1Transaction for Server {
|
||||
// a good ~5% on pipeline benchmarks.
|
||||
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());
|
||||
let mut req = httparse::Request::new(&mut headers);
|
||||
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!(
|
||||
"Server::encode status={:?}, body={:?}, req_method={:?}",
|
||||
msg.head.subject,
|
||||
@@ -589,7 +588,7 @@ impl Http1Transaction for Client {
|
||||
type Outgoing = RequestLine;
|
||||
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 {
|
||||
if buf.is_empty() {
|
||||
@@ -598,7 +597,7 @@ impl Http1Transaction for Client {
|
||||
// Unsafe: see comment in Server Http1Transaction, above.
|
||||
let mut headers_indices: [HeaderIndices; MAX_HEADERS] = unsafe { mem::uninitialized() };
|
||||
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());
|
||||
let mut res = httparse::Response::new(&mut headers);
|
||||
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);
|
||||
|
||||
*msg.req_method = Some(msg.head.subject.0.clone());
|
||||
@@ -935,7 +934,7 @@ struct HeaderIndices {
|
||||
|
||||
fn record_header_indices(
|
||||
bytes: &[u8],
|
||||
headers: &[httparse::Header],
|
||||
headers: &[httparse::Header<'_>],
|
||||
indices: &mut [HeaderIndices]
|
||||
) -> Result<(), crate::error::Parse> {
|
||||
let bytes_ptr = bytes.as_ptr() as usize;
|
||||
@@ -1044,7 +1043,7 @@ impl<'a> fmt::Write for FastWrite<'a> {
|
||||
}
|
||||
|
||||
#[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)
|
||||
}
|
||||
}
|
||||
@@ -1062,7 +1061,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_parse_request() {
|
||||
extern crate pretty_env_logger;
|
||||
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 method = None;
|
||||
@@ -1082,7 +1080,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_parse_response() {
|
||||
extern crate pretty_env_logger;
|
||||
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 ctx = ParseContext {
|
||||
|
||||
Reference in New Issue
Block a user