diff --git a/Cargo.toml b/Cargo.toml index c2e1eb94fe..aecca58bb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ httparse = { git = "https://github.com/BenxiangGe/httparse.git", version = "1.3. h2 = { git = "https://github.com/BenxiangGe/h2.git", version = "0.2.2" } itoa = "0.4.1" log = "0.4" -pin-project = "0.4" +pin-project = "0.4.17" time = "0.1" tower-service = "0.3" tokio = { version = "0.2.5", features = ["sync"] } diff --git a/src/client/conn.rs b/src/client/conn.rs index 7131270436..2383d5c907 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -17,7 +17,7 @@ use std::time::Duration; use bytes::Bytes; use futures_util::future::{self, Either, FutureExt as _}; -use pin_project::{pin_project, project}; +use pin_project::pin_project; use tokio::io::{AsyncRead, AsyncWrite}; use tower_service::Service; @@ -30,7 +30,7 @@ use crate::{Body, Request, Response}; type Http1Dispatcher = proto::dispatch::Dispatcher, B, T, R>; -#[pin_project] +#[pin_project(project = ProtoClientProj)] enum ProtoClient where B: HttpBody, @@ -677,12 +677,10 @@ where { type Output = crate::Result; - #[project] fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { - #[project] match self.project() { - ProtoClient::H1(c) => c.poll(cx), - ProtoClient::H2(c) => c.poll(cx), + ProtoClientProj::H1(c) => c.poll(cx), + ProtoClientProj::H2(c) => c.poll(cx), } } } diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index 4762a9209a..1bbc964672 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -5,7 +5,7 @@ use std::time::Duration; use h2::server::{Connection, Handshake, SendResponse}; use h2::Reason; -use pin_project::{pin_project, project}; +use pin_project::pin_project; use tokio::io::{AsyncRead, AsyncWrite}; use super::{decode_content_length, ping, PipeToSendStream, SendBuf}; @@ -326,7 +326,7 @@ where state: H2StreamState, } -#[pin_project] +#[pin_project(project = H2StreamStateProj)] enum H2StreamState where B: HttpBody, @@ -367,13 +367,11 @@ where B::Error: Into>, E: Into>, { - #[project] fn poll2(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll> { let mut me = self.project(); loop { - #[project] let next = match me.state.as_mut().project() { - H2StreamState::Service(h) => { + H2StreamStateProj::Service(h) => { let res = match h.poll(cx) { Poll::Ready(Ok(r)) => r, Poll::Pending => { @@ -417,7 +415,7 @@ where return Poll::Ready(Ok(())); } } - H2StreamState::Body(pipe) => { + H2StreamStateProj::Body(pipe) => { return pipe.poll(cx); } }; diff --git a/src/server/conn.rs b/src/server/conn.rs index 76fac003bc..e0235b6ae9 100644 --- a/src/server/conn.rs +++ b/src/server/conn.rs @@ -17,7 +17,7 @@ use std::net::SocketAddr; use std::time::Duration; use bytes::Bytes; -use pin_project::{pin_project, project}; +use pin_project::pin_project; use tokio::io::{AsyncRead, AsyncWrite}; use super::Accept; @@ -118,7 +118,7 @@ where fallback: Fallback, } -#[pin_project] +#[pin_project(project = ProtoServerProj)] pub(super) enum ProtoServer where S: HttpService, @@ -836,12 +836,10 @@ where { type Output = crate::Result; - #[project] fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { - #[project] match self.project() { - ProtoServer::H1(s) => s.poll(cx), - ProtoServer::H2(s) => s.poll(cx), + ProtoServerProj::H1(s) => s.poll(cx), + ProtoServerProj::H2(s) => s.poll(cx), } } } @@ -855,7 +853,7 @@ pub(crate) mod spawn_all { use crate::common::exec::H2Exec; use crate::common::{task, Future, Pin, Poll, Unpin}; use crate::service::HttpService; - use pin_project::{pin_project, project}; + use pin_project::pin_project; // Used by `SpawnAll` to optionally watch a `Connection` future. // @@ -907,7 +905,7 @@ pub(crate) mod spawn_all { state: State, } - #[pin_project] + #[pin_project(project = StateProj)] pub enum State, E, W: Watcher> { Connecting(#[pin] Connecting, W), Connected(#[pin] W::Future), @@ -934,7 +932,6 @@ pub(crate) mod spawn_all { { type Output = (); - #[project] fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { // If it weren't for needing to name this type so the `Send` bounds // could be projected to the `Serve` executor, this could just be @@ -943,9 +940,8 @@ pub(crate) mod spawn_all { let mut me = self.project(); loop { let next = { - #[project] match me.state.as_mut().project() { - State::Connecting(connecting, watcher) => { + StateProj::Connecting(connecting, watcher) => { let res = ready!(connecting.poll(cx)); let conn = match res { Ok(conn) => conn, @@ -958,7 +954,7 @@ pub(crate) mod spawn_all { let connected = watcher.watch(conn.with_upgrades()); State::Connected(connected) } - State::Connected(future) => { + StateProj::Connected(future) => { return future.poll(cx).map(|res| { if let Err(err) = res { debug!("connection error: {}", err); diff --git a/src/server/shutdown.rs b/src/server/shutdown.rs index 6a8d32cc0b..543859379a 100644 --- a/src/server/shutdown.rs +++ b/src/server/shutdown.rs @@ -1,6 +1,6 @@ use std::error::Error as StdError; -use pin_project::{pin_project, project}; +use pin_project::pin_project; use tokio::io::{AsyncRead, AsyncWrite}; use super::conn::{SpawnAll, UpgradeableConnection, Watcher}; @@ -18,7 +18,7 @@ pub struct Graceful { state: State, } -#[pin_project] +#[pin_project(project = StateProj)] pub(super) enum State { Running { drain: Option<(Signal, Watch)>, @@ -58,14 +58,12 @@ where { type Output = crate::Result<()>; - #[project] fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { let mut me = self.project(); loop { let next = { - #[project] match me.state.as_mut().project() { - State::Running { + StateProj::Running { drain, spawn_all, signal, @@ -80,7 +78,7 @@ where return spawn_all.poll_watch(cx, &GracefulWatcher(watch)); } }, - State::Draining(ref mut draining) => { + StateProj::Draining(ref mut draining) => { return Pin::new(draining).poll(cx).map(Ok); } }