fix: Remove uses of pin_project::project attribute (#367)
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:
+1
-1
@@ -141,7 +141,7 @@ hyper = "0.13"
|
|||||||
warp = { version = "0.2", default-features = false }
|
warp = { version = "0.2", default-features = false }
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
http-body = "0.3"
|
http-body = "0.3"
|
||||||
pin-project = "0.4"
|
pin-project = "0.4.17"
|
||||||
# Health example
|
# Health example
|
||||||
tonic-health = { path = "../tonic-health" }
|
tonic-health = { path = "../tonic-health" }
|
||||||
listenfd = "0.3"
|
listenfd = "0.3"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
use futures::future::{self, Either, TryFutureExt};
|
use futures::future::{self, Either, TryFutureExt};
|
||||||
use http::version::Version;
|
use http::version::Version;
|
||||||
use hyper::{service::make_service_fn, Server};
|
use hyper::{service::make_service_fn, Server};
|
||||||
use pin_project::{pin_project, project};
|
use pin_project::pin_project;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::{
|
use std::{
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
@@ -77,7 +77,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project]
|
#[pin_project(project = EitherBodyProj)]
|
||||||
enum EitherBody<A, B> {
|
enum EitherBody<A, B> {
|
||||||
Left(#[pin] A),
|
Left(#[pin] A),
|
||||||
Right(#[pin] B),
|
Right(#[pin] B),
|
||||||
@@ -100,27 +100,23 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[project]
|
|
||||||
fn poll_data(
|
fn poll_data(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
|
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
|
||||||
#[project]
|
|
||||||
match self.project() {
|
match self.project() {
|
||||||
EitherBody::Left(b) => b.poll_data(cx).map(map_option_err),
|
EitherBodyProj::Left(b) => b.poll_data(cx).map(map_option_err),
|
||||||
EitherBody::Right(b) => b.poll_data(cx).map(map_option_err),
|
EitherBodyProj::Right(b) => b.poll_data(cx).map(map_option_err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[project]
|
|
||||||
fn poll_trailers(
|
fn poll_trailers(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
) -> Poll<Result<Option<http::HeaderMap>, Self::Error>> {
|
) -> Poll<Result<Option<http::HeaderMap>, Self::Error>> {
|
||||||
#[project]
|
|
||||||
match self.project() {
|
match self.project() {
|
||||||
EitherBody::Left(b) => b.poll_trailers(cx).map_err(Into::into),
|
EitherBodyProj::Left(b) => b.poll_trailers(cx).map_err(Into::into),
|
||||||
EitherBody::Right(b) => b.poll_trailers(cx).map_err(Into::into),
|
EitherBodyProj::Right(b) => b.poll_trailers(cx).map_err(Into::into),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ tower-service = "0.3"
|
|||||||
tokio-util = { version = "0.3", features = ["codec"] }
|
tokio-util = { version = "0.3", features = ["codec"] }
|
||||||
async-stream = "0.2"
|
async-stream = "0.2"
|
||||||
http-body = "0.3"
|
http-body = "0.3"
|
||||||
pin-project = "0.4"
|
pin-project = "0.4.17"
|
||||||
|
|
||||||
# prost
|
# prost
|
||||||
prost1 = { package = "prost", version = "0.6", optional = true }
|
prost1 = { package = "prost", version = "0.6", optional = true }
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::Error;
|
use crate::Error;
|
||||||
use pin_project::{pin_project, project};
|
use pin_project::pin_project;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
||||||
@@ -161,7 +161,7 @@ pub(crate) struct ResponseFuture<F, E> {
|
|||||||
inner: Inner<F, E>,
|
inner: Inner<F, E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project]
|
#[pin_project(project = InnerProj)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Inner<F, E> {
|
enum Inner<F, E> {
|
||||||
Future(#[pin] F),
|
Future(#[pin] F),
|
||||||
@@ -190,14 +190,12 @@ where
|
|||||||
{
|
{
|
||||||
type Output = Result<T, Error>;
|
type Output = Result<T, Error>;
|
||||||
|
|
||||||
#[project]
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
//self.project().inner.poll(cx).map_err(Into::into)
|
//self.project().inner.poll(cx).map_err(Into::into)
|
||||||
let me = self.project();
|
let me = self.project();
|
||||||
#[project]
|
|
||||||
match me.inner.project() {
|
match me.inner.project() {
|
||||||
Inner::Future(fut) => fut.poll(cx).map_err(Into::into),
|
InnerProj::Future(fut) => fut.poll(cx).map_err(Into::into),
|
||||||
Inner::Error(e) => {
|
InnerProj::Error(e) => {
|
||||||
let e = e.take().expect("Polled after ready.").into();
|
let e = e.take().expect("Polled after ready.").into();
|
||||||
Poll::Ready(Err(e))
|
Poll::Ready(Err(e))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user