Skip to content

Commit 3168177

Browse files
taiki-eBenxiang Ge
authored and
Benxiang Ge
committed
refactor(lib): Remove uses of pin_project::project attribute (hyperium#2219)
pin-project will deprecate the project attribute due to some unfixable limitations. Refs: taiki-e/pin-project#225
1 parent 7f2ecb3 commit 3168177

File tree

5 files changed

+21
-31
lines changed

5 files changed

+21
-31
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ httparse = { git = "https://github.com/BenxiangGe/httparse.git", version = "1.3.
3030
h2 = { git = "https://github.com/BenxiangGe/h2.git", version = "0.2.2" }
3131
itoa = "0.4.1"
3232
log = "0.4"
33-
pin-project = "0.4"
33+
pin-project = "0.4.17"
3434
time = "0.1"
3535
tower-service = "0.3"
3636
tokio = { version = "0.2.5", features = ["sync"] }

src/client/conn.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::time::Duration;
1717

1818
use bytes::Bytes;
1919
use futures_util::future::{self, Either, FutureExt as _};
20-
use pin_project::{pin_project, project};
20+
use pin_project::pin_project;
2121
use tokio::io::{AsyncRead, AsyncWrite};
2222
use tower_service::Service;
2323

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

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

33-
#[pin_project]
33+
#[pin_project(project = ProtoClientProj)]
3434
enum ProtoClient<T, B>
3535
where
3636
B: HttpBody,
@@ -677,12 +677,10 @@ where
677677
{
678678
type Output = crate::Result<proto::Dispatched>;
679679

680-
#[project]
681680
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
682-
#[project]
683681
match self.project() {
684-
ProtoClient::H1(c) => c.poll(cx),
685-
ProtoClient::H2(c) => c.poll(cx),
682+
ProtoClientProj::H1(c) => c.poll(cx),
683+
ProtoClientProj::H2(c) => c.poll(cx),
686684
}
687685
}
688686
}

src/proto/h2/server.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::time::Duration;
55

66
use h2::server::{Connection, Handshake, SendResponse};
77
use h2::Reason;
8-
use pin_project::{pin_project, project};
8+
use pin_project::pin_project;
99
use tokio::io::{AsyncRead, AsyncWrite};
1010

1111
use super::{decode_content_length, ping, PipeToSendStream, SendBuf};
@@ -326,7 +326,7 @@ where
326326
state: H2StreamState<F, B>,
327327
}
328328

329-
#[pin_project]
329+
#[pin_project(project = H2StreamStateProj)]
330330
enum H2StreamState<F, B>
331331
where
332332
B: HttpBody,
@@ -367,13 +367,11 @@ where
367367
B::Error: Into<Box<dyn StdError + Send + Sync>>,
368368
E: Into<Box<dyn StdError + Send + Sync>>,
369369
{
370-
#[project]
371370
fn poll2(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
372371
let mut me = self.project();
373372
loop {
374-
#[project]
375373
let next = match me.state.as_mut().project() {
376-
H2StreamState::Service(h) => {
374+
H2StreamStateProj::Service(h) => {
377375
let res = match h.poll(cx) {
378376
Poll::Ready(Ok(r)) => r,
379377
Poll::Pending => {
@@ -417,7 +415,7 @@ where
417415
return Poll::Ready(Ok(()));
418416
}
419417
}
420-
H2StreamState::Body(pipe) => {
418+
H2StreamStateProj::Body(pipe) => {
421419
return pipe.poll(cx);
422420
}
423421
};

src/server/conn.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::net::SocketAddr;
1717
use std::time::Duration;
1818

1919
use bytes::Bytes;
20-
use pin_project::{pin_project, project};
20+
use pin_project::pin_project;
2121
use tokio::io::{AsyncRead, AsyncWrite};
2222

2323
use super::Accept;
@@ -118,7 +118,7 @@ where
118118
fallback: Fallback<E>,
119119
}
120120

121-
#[pin_project]
121+
#[pin_project(project = ProtoServerProj)]
122122
pub(super) enum ProtoServer<T, B, S, E = Exec>
123123
where
124124
S: HttpService<Body>,
@@ -836,12 +836,10 @@ where
836836
{
837837
type Output = crate::Result<proto::Dispatched>;
838838

839-
#[project]
840839
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
841-
#[project]
842840
match self.project() {
843-
ProtoServer::H1(s) => s.poll(cx),
844-
ProtoServer::H2(s) => s.poll(cx),
841+
ProtoServerProj::H1(s) => s.poll(cx),
842+
ProtoServerProj::H2(s) => s.poll(cx),
845843
}
846844
}
847845
}
@@ -855,7 +853,7 @@ pub(crate) mod spawn_all {
855853
use crate::common::exec::H2Exec;
856854
use crate::common::{task, Future, Pin, Poll, Unpin};
857855
use crate::service::HttpService;
858-
use pin_project::{pin_project, project};
856+
use pin_project::pin_project;
859857

860858
// Used by `SpawnAll` to optionally watch a `Connection` future.
861859
//
@@ -907,7 +905,7 @@ pub(crate) mod spawn_all {
907905
state: State<I, N, S, E, W>,
908906
}
909907

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

937-
#[project]
938935
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
939936
// If it weren't for needing to name this type so the `Send` bounds
940937
// could be projected to the `Serve` executor, this could just be
@@ -943,9 +940,8 @@ pub(crate) mod spawn_all {
943940
let mut me = self.project();
944941
loop {
945942
let next = {
946-
#[project]
947943
match me.state.as_mut().project() {
948-
State::Connecting(connecting, watcher) => {
944+
StateProj::Connecting(connecting, watcher) => {
949945
let res = ready!(connecting.poll(cx));
950946
let conn = match res {
951947
Ok(conn) => conn,
@@ -958,7 +954,7 @@ pub(crate) mod spawn_all {
958954
let connected = watcher.watch(conn.with_upgrades());
959955
State::Connected(connected)
960956
}
961-
State::Connected(future) => {
957+
StateProj::Connected(future) => {
962958
return future.poll(cx).map(|res| {
963959
if let Err(err) = res {
964960
debug!("connection error: {}", err);

src/server/shutdown.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::error::Error as StdError;
22

3-
use pin_project::{pin_project, project};
3+
use pin_project::pin_project;
44
use tokio::io::{AsyncRead, AsyncWrite};
55

66
use super::conn::{SpawnAll, UpgradeableConnection, Watcher};
@@ -18,7 +18,7 @@ pub struct Graceful<I, S, F, E> {
1818
state: State<I, S, F, E>,
1919
}
2020

21-
#[pin_project]
21+
#[pin_project(project = StateProj)]
2222
pub(super) enum State<I, S, F, E> {
2323
Running {
2424
drain: Option<(Signal, Watch)>,
@@ -58,14 +58,12 @@ where
5858
{
5959
type Output = crate::Result<()>;
6060

61-
#[project]
6261
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
6362
let mut me = self.project();
6463
loop {
6564
let next = {
66-
#[project]
6765
match me.state.as_mut().project() {
68-
State::Running {
66+
StateProj::Running {
6967
drain,
7068
spawn_all,
7169
signal,
@@ -80,7 +78,7 @@ where
8078
return spawn_all.poll_watch(cx, &GracefulWatcher(watch));
8179
}
8280
},
83-
State::Draining(ref mut draining) => {
81+
StateProj::Draining(ref mut draining) => {
8482
return Pin::new(draining).poll(cx).map(Ok);
8583
}
8684
}

0 commit comments

Comments
 (0)