Skip to content

Commit

Permalink
refactor(lib): Remove uses of pin_project::project attribute (#2219)
Browse files Browse the repository at this point in the history
pin-project will deprecate the project attribute due to some unfixable
limitations.

Refs: taiki-e/pin-project#225
  • Loading branch information
taiki-e authored Jun 5, 2020
1 parent 2354a7e commit d5d09ed
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ httparse = "1.0"
h2 = "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"] }
Expand Down
10 changes: 4 additions & 6 deletions src/client/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,7 +30,7 @@ use crate::{Body, Request, Response};

type Http1Dispatcher<T, B, R> = proto::dispatch::Dispatcher<proto::dispatch::Client<B>, B, T, R>;

#[pin_project]
#[pin_project(project = ProtoClientProj)]
enum ProtoClient<T, B>
where
B: HttpBody,
Expand Down Expand Up @@ -677,12 +677,10 @@ where
{
type Output = crate::Result<proto::Dispatched>;

#[project]
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
#[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),
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/proto/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -326,7 +326,7 @@ where
state: H2StreamState<F, B>,
}

#[pin_project]
#[pin_project(project = H2StreamStateProj)]
enum H2StreamState<F, B>
where
B: HttpBody,
Expand Down Expand Up @@ -367,13 +367,11 @@ where
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: Into<Box<dyn StdError + Send + Sync>>,
{
#[project]
fn poll2(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
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 => {
Expand Down Expand Up @@ -417,7 +415,7 @@ where
return Poll::Ready(Ok(()));
}
}
H2StreamState::Body(pipe) => {
H2StreamStateProj::Body(pipe) => {
return pipe.poll(cx);
}
};
Expand Down
20 changes: 8 additions & 12 deletions src/server/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +118,7 @@ where
fallback: Fallback<E>,
}

#[pin_project]
#[pin_project(project = ProtoServerProj)]
pub(super) enum ProtoServer<T, B, S, E = Exec>
where
S: HttpService<Body>,
Expand Down Expand Up @@ -836,12 +836,10 @@ where
{
type Output = crate::Result<proto::Dispatched>;

#[project]
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
#[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),
}
}
}
Expand All @@ -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.
//
Expand Down Expand Up @@ -907,7 +905,7 @@ pub(crate) mod spawn_all {
state: State<I, N, S, E, W>,
}

#[pin_project]
#[pin_project(project = StateProj)]
pub enum State<I, N, S: HttpService<Body>, E, W: Watcher<I, S, E>> {
Connecting(#[pin] Connecting<I, N, E>, W),
Connected(#[pin] W::Future),
Expand All @@ -934,7 +932,6 @@ pub(crate) mod spawn_all {
{
type Output = ();

#[project]
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
// 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
Expand All @@ -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,
Expand All @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions src/server/shutdown.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -18,7 +18,7 @@ pub struct Graceful<I, S, F, E> {
state: State<I, S, F, E>,
}

#[pin_project]
#[pin_project(project = StateProj)]
pub(super) enum State<I, S, F, E> {
Running {
drain: Option<(Signal, Watch)>,
Expand Down Expand Up @@ -58,14 +58,12 @@ where
{
type Output = crate::Result<()>;

#[project]
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
let mut me = self.project();
loop {
let next = {
#[project]
match me.state.as_mut().project() {
State::Running {
StateProj::Running {
drain,
spawn_all,
signal,
Expand All @@ -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);
}
}
Expand Down

0 comments on commit d5d09ed

Please sign in to comment.