refactor(lib): Remove uses of pin_project::project attribute (#2219)
pin-project will deprecate the project attribute due to some unfixable limitations. Refs: https://github.com/taiki-e/pin-project/issues/225
This commit is contained in:
@@ -30,7 +30,7 @@ httparse = "1.0"
|
|||||||
h2 = "0.2.2"
|
h2 = "0.2.2"
|
||||||
itoa = "0.4.1"
|
itoa = "0.4.1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pin-project = "0.4"
|
pin-project = "0.4.17"
|
||||||
time = "0.1"
|
time = "0.1"
|
||||||
tower-service = "0.3"
|
tower-service = "0.3"
|
||||||
tokio = { version = "0.2.5", features = ["sync"] }
|
tokio = { version = "0.2.5", features = ["sync"] }
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_util::future::{self, Either, FutureExt as _};
|
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 tokio::io::{AsyncRead, AsyncWrite};
|
||||||
use tower_service::Service;
|
use tower_service::Service;
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ use crate::{Body, Request, Response};
|
|||||||
|
|
||||||
type Http1Dispatcher<T, B, R> = proto::dispatch::Dispatcher<proto::dispatch::Client<B>, B, T, R>;
|
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>
|
enum ProtoClient<T, B>
|
||||||
where
|
where
|
||||||
B: HttpBody,
|
B: HttpBody,
|
||||||
@@ -677,12 +677,10 @@ where
|
|||||||
{
|
{
|
||||||
type Output = crate::Result<proto::Dispatched>;
|
type Output = crate::Result<proto::Dispatched>;
|
||||||
|
|
||||||
#[project]
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
|
||||||
#[project]
|
|
||||||
match self.project() {
|
match self.project() {
|
||||||
ProtoClient::H1(c) => c.poll(cx),
|
ProtoClientProj::H1(c) => c.poll(cx),
|
||||||
ProtoClient::H2(c) => c.poll(cx),
|
ProtoClientProj::H2(c) => c.poll(cx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use h2::server::{Connection, Handshake, SendResponse};
|
use h2::server::{Connection, Handshake, SendResponse};
|
||||||
use h2::Reason;
|
use h2::Reason;
|
||||||
use pin_project::{pin_project, project};
|
use pin_project::pin_project;
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
|
|
||||||
use super::{decode_content_length, ping, PipeToSendStream, SendBuf};
|
use super::{decode_content_length, ping, PipeToSendStream, SendBuf};
|
||||||
@@ -326,7 +326,7 @@ where
|
|||||||
state: H2StreamState<F, B>,
|
state: H2StreamState<F, B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project]
|
#[pin_project(project = H2StreamStateProj)]
|
||||||
enum H2StreamState<F, B>
|
enum H2StreamState<F, B>
|
||||||
where
|
where
|
||||||
B: HttpBody,
|
B: HttpBody,
|
||||||
@@ -367,13 +367,11 @@ where
|
|||||||
B::Error: Into<Box<dyn StdError + Send + Sync>>,
|
B::Error: Into<Box<dyn StdError + Send + Sync>>,
|
||||||
E: 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<()>> {
|
fn poll2(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
|
||||||
let mut me = self.project();
|
let mut me = self.project();
|
||||||
loop {
|
loop {
|
||||||
#[project]
|
|
||||||
let next = match me.state.as_mut().project() {
|
let next = match me.state.as_mut().project() {
|
||||||
H2StreamState::Service(h) => {
|
H2StreamStateProj::Service(h) => {
|
||||||
let res = match h.poll(cx) {
|
let res = match h.poll(cx) {
|
||||||
Poll::Ready(Ok(r)) => r,
|
Poll::Ready(Ok(r)) => r,
|
||||||
Poll::Pending => {
|
Poll::Pending => {
|
||||||
@@ -417,7 +415,7 @@ where
|
|||||||
return Poll::Ready(Ok(()));
|
return Poll::Ready(Ok(()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
H2StreamState::Body(pipe) => {
|
H2StreamStateProj::Body(pipe) => {
|
||||||
return pipe.poll(cx);
|
return pipe.poll(cx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use std::net::SocketAddr;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use pin_project::{pin_project, project};
|
use pin_project::pin_project;
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
|
|
||||||
use super::Accept;
|
use super::Accept;
|
||||||
@@ -118,7 +118,7 @@ where
|
|||||||
fallback: Fallback<E>,
|
fallback: Fallback<E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project]
|
#[pin_project(project = ProtoServerProj)]
|
||||||
pub(super) enum ProtoServer<T, B, S, E = Exec>
|
pub(super) enum ProtoServer<T, B, S, E = Exec>
|
||||||
where
|
where
|
||||||
S: HttpService<Body>,
|
S: HttpService<Body>,
|
||||||
@@ -836,12 +836,10 @@ where
|
|||||||
{
|
{
|
||||||
type Output = crate::Result<proto::Dispatched>;
|
type Output = crate::Result<proto::Dispatched>;
|
||||||
|
|
||||||
#[project]
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
|
||||||
#[project]
|
|
||||||
match self.project() {
|
match self.project() {
|
||||||
ProtoServer::H1(s) => s.poll(cx),
|
ProtoServerProj::H1(s) => s.poll(cx),
|
||||||
ProtoServer::H2(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::exec::H2Exec;
|
||||||
use crate::common::{task, Future, Pin, Poll, Unpin};
|
use crate::common::{task, Future, Pin, Poll, Unpin};
|
||||||
use crate::service::HttpService;
|
use crate::service::HttpService;
|
||||||
use pin_project::{pin_project, project};
|
use pin_project::pin_project;
|
||||||
|
|
||||||
// Used by `SpawnAll` to optionally watch a `Connection` future.
|
// Used by `SpawnAll` to optionally watch a `Connection` future.
|
||||||
//
|
//
|
||||||
@@ -907,7 +905,7 @@ pub(crate) mod spawn_all {
|
|||||||
state: State<I, N, S, E, W>,
|
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>> {
|
pub enum State<I, N, S: HttpService<Body>, E, W: Watcher<I, S, E>> {
|
||||||
Connecting(#[pin] Connecting<I, N, E>, W),
|
Connecting(#[pin] Connecting<I, N, E>, W),
|
||||||
Connected(#[pin] W::Future),
|
Connected(#[pin] W::Future),
|
||||||
@@ -934,7 +932,6 @@ pub(crate) mod spawn_all {
|
|||||||
{
|
{
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
#[project]
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
|
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
|
// 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
|
// 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();
|
let mut me = self.project();
|
||||||
loop {
|
loop {
|
||||||
let next = {
|
let next = {
|
||||||
#[project]
|
|
||||||
match me.state.as_mut().project() {
|
match me.state.as_mut().project() {
|
||||||
State::Connecting(connecting, watcher) => {
|
StateProj::Connecting(connecting, watcher) => {
|
||||||
let res = ready!(connecting.poll(cx));
|
let res = ready!(connecting.poll(cx));
|
||||||
let conn = match res {
|
let conn = match res {
|
||||||
Ok(conn) => conn,
|
Ok(conn) => conn,
|
||||||
@@ -958,7 +954,7 @@ pub(crate) mod spawn_all {
|
|||||||
let connected = watcher.watch(conn.with_upgrades());
|
let connected = watcher.watch(conn.with_upgrades());
|
||||||
State::Connected(connected)
|
State::Connected(connected)
|
||||||
}
|
}
|
||||||
State::Connected(future) => {
|
StateProj::Connected(future) => {
|
||||||
return future.poll(cx).map(|res| {
|
return future.poll(cx).map(|res| {
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
debug!("connection error: {}", err);
|
debug!("connection error: {}", err);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::error::Error as StdError;
|
use std::error::Error as StdError;
|
||||||
|
|
||||||
use pin_project::{pin_project, project};
|
use pin_project::pin_project;
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
|
|
||||||
use super::conn::{SpawnAll, UpgradeableConnection, Watcher};
|
use super::conn::{SpawnAll, UpgradeableConnection, Watcher};
|
||||||
@@ -18,7 +18,7 @@ pub struct Graceful<I, S, F, E> {
|
|||||||
state: State<I, S, F, E>,
|
state: State<I, S, F, E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project]
|
#[pin_project(project = StateProj)]
|
||||||
pub(super) enum State<I, S, F, E> {
|
pub(super) enum State<I, S, F, E> {
|
||||||
Running {
|
Running {
|
||||||
drain: Option<(Signal, Watch)>,
|
drain: Option<(Signal, Watch)>,
|
||||||
@@ -58,14 +58,12 @@ where
|
|||||||
{
|
{
|
||||||
type Output = crate::Result<()>;
|
type Output = crate::Result<()>;
|
||||||
|
|
||||||
#[project]
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
|
||||||
let mut me = self.project();
|
let mut me = self.project();
|
||||||
loop {
|
loop {
|
||||||
let next = {
|
let next = {
|
||||||
#[project]
|
|
||||||
match me.state.as_mut().project() {
|
match me.state.as_mut().project() {
|
||||||
State::Running {
|
StateProj::Running {
|
||||||
drain,
|
drain,
|
||||||
spawn_all,
|
spawn_all,
|
||||||
signal,
|
signal,
|
||||||
@@ -80,7 +78,7 @@ where
|
|||||||
return spawn_all.poll_watch(cx, &GracefulWatcher(watch));
|
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);
|
return Pin::new(draining).poll(cx).map(Ok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user