Remove uses of pin_project::project attribute (#458)
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:
parent
007b648ea9
commit
b12a3e3ae9
|
@ -27,7 +27,7 @@ tokio = { version = "0.2", features = ["sync"]}
|
|||
tower-layer = { version = "0.3", path = "../tower-layer" }
|
||||
tokio-test = "0.2"
|
||||
tower-service = { version = "0.3" }
|
||||
pin-project = "0.4"
|
||||
pin-project = "0.4.17"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "0.2", features = ["macros"] }
|
||||
|
|
|
@ -45,7 +45,7 @@ util = ["futures-util"]
|
|||
|
||||
[dependencies]
|
||||
futures-core = "0.3"
|
||||
pin-project = "0.4"
|
||||
pin-project = "0.4.17"
|
||||
tower-layer = { version = "0.3", path = "../tower-layer" }
|
||||
tower-service = { version = "0.3" }
|
||||
tracing = "0.1.2"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use super::{error::Closed, message};
|
||||
use futures_core::ready;
|
||||
use pin_project::{pin_project, project};
|
||||
use pin_project::pin_project;
|
||||
use std::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
|
@ -17,7 +17,7 @@ pub struct ResponseFuture<T> {
|
|||
state: ResponseState<T>,
|
||||
}
|
||||
|
||||
#[pin_project]
|
||||
#[pin_project(project = ResponseStateProj)]
|
||||
#[derive(Debug)]
|
||||
enum ResponseState<T> {
|
||||
Failed(Option<crate::BoxError>),
|
||||
|
@ -46,22 +46,20 @@ where
|
|||
{
|
||||
type Output = Result<T, crate::BoxError>;
|
||||
|
||||
#[project]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let mut this = self.project();
|
||||
|
||||
loop {
|
||||
#[project]
|
||||
match this.state.as_mut().project() {
|
||||
ResponseState::Failed(e) => {
|
||||
ResponseStateProj::Failed(e) => {
|
||||
return Poll::Ready(Err(e.take().expect("polled after error")));
|
||||
}
|
||||
ResponseState::Rx(rx) => match ready!(rx.poll(cx)) {
|
||||
ResponseStateProj::Rx(rx) => match ready!(rx.poll(cx)) {
|
||||
Ok(Ok(f)) => this.state.set(ResponseState::Poll(f)),
|
||||
Ok(Err(e)) => return Poll::Ready(Err(e.into())),
|
||||
Err(_) => return Poll::Ready(Err(Closed::new().into())),
|
||||
},
|
||||
ResponseState::Poll(fut) => return fut.poll(cx).map_err(Into::into),
|
||||
ResponseStateProj::Poll(fut) => return fut.poll(cx).map_err(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use super::error::Error;
|
||||
use futures_core::ready;
|
||||
use pin_project::{pin_project, project};
|
||||
use pin_project::pin_project;
|
||||
use std::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
|
@ -29,7 +29,7 @@ where
|
|||
service: S,
|
||||
}
|
||||
|
||||
#[pin_project]
|
||||
#[pin_project(project = StateProj)]
|
||||
#[derive(Debug)]
|
||||
enum State<Request, U> {
|
||||
Check(Option<Request>),
|
||||
|
@ -59,14 +59,12 @@ where
|
|||
{
|
||||
type Output = Result<S::Response, Error>;
|
||||
|
||||
#[project]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let mut this = self.project();
|
||||
|
||||
loop {
|
||||
#[project]
|
||||
match this.state.as_mut().project() {
|
||||
State::Check(request) => {
|
||||
StateProj::Check(request) => {
|
||||
let request = request
|
||||
.take()
|
||||
.expect("we either give it back or leave State::Check once we take");
|
||||
|
@ -83,7 +81,7 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
State::WaitResponse(response) => {
|
||||
StateProj::WaitResponse(response) => {
|
||||
return Poll::Ready(ready!(response.poll(cx)).map_err(Error::inner));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use futures_util::ready;
|
||||
use pin_project::{pin_project, project};
|
||||
use pin_project::pin_project;
|
||||
use std::time::Duration;
|
||||
use std::{
|
||||
future::Future,
|
||||
|
@ -29,7 +29,7 @@ pub struct ResponseFuture<Request, S, F> {
|
|||
state: State<Request, F>,
|
||||
}
|
||||
|
||||
#[pin_project]
|
||||
#[pin_project(project = StateProj)]
|
||||
#[derive(Debug)]
|
||||
enum State<Request, F> {
|
||||
Delaying(#[pin] tokio::time::Delay, Option<Request>),
|
||||
|
@ -84,20 +84,18 @@ where
|
|||
{
|
||||
type Output = Result<T, crate::BoxError>;
|
||||
|
||||
#[project]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let mut this = self.project();
|
||||
|
||||
loop {
|
||||
#[project]
|
||||
match this.state.as_mut().project() {
|
||||
State::Delaying(delay, req) => {
|
||||
StateProj::Delaying(delay, req) => {
|
||||
ready!(delay.poll(cx));
|
||||
let req = req.take().expect("Missing request in delay");
|
||||
let fut = this.service.call(req);
|
||||
this.state.set(State::Called(fut));
|
||||
}
|
||||
State::Called(fut) => {
|
||||
StateProj::Called(fut) => {
|
||||
return fut.poll(cx).map_err(Into::into);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::pin::Pin;
|
|||
use std::task::{Context, Poll};
|
||||
|
||||
use futures_core::ready;
|
||||
use pin_project::{pin_project, project};
|
||||
use pin_project::pin_project;
|
||||
|
||||
use super::error::Overloaded;
|
||||
|
||||
|
@ -17,7 +17,7 @@ pub struct ResponseFuture<F> {
|
|||
state: ResponseState<F>,
|
||||
}
|
||||
|
||||
#[pin_project]
|
||||
#[pin_project(project = ResponseStateProj)]
|
||||
enum ResponseState<F> {
|
||||
Called(#[pin] F),
|
||||
Overloaded,
|
||||
|
@ -44,12 +44,10 @@ where
|
|||
{
|
||||
type Output = Result<T, crate::BoxError>;
|
||||
|
||||
#[project]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
#[project]
|
||||
match self.project().state.project() {
|
||||
ResponseState::Called(fut) => Poll::Ready(ready!(fut.poll(cx)).map_err(Into::into)),
|
||||
ResponseState::Overloaded => Poll::Ready(Err(Overloaded::new().into())),
|
||||
ResponseStateProj::Called(fut) => Poll::Ready(ready!(fut.poll(cx)).map_err(Into::into)),
|
||||
ResponseStateProj::Overloaded => Poll::Ready(Err(Overloaded::new().into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use pin_project::{pin_project, project};
|
||||
use pin_project::pin_project;
|
||||
use std::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
|
@ -13,7 +13,7 @@ pub struct ResponseFuture<F, E> {
|
|||
inner: Inner<F, E>,
|
||||
}
|
||||
|
||||
#[pin_project]
|
||||
#[pin_project(project = InnerProj)]
|
||||
#[derive(Debug)]
|
||||
enum Inner<F, E> {
|
||||
Future(#[pin] F),
|
||||
|
@ -42,13 +42,11 @@ where
|
|||
{
|
||||
type Output = Result<T, crate::BoxError>;
|
||||
|
||||
#[project]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let me = self.project();
|
||||
#[project]
|
||||
match me.inner.project() {
|
||||
Inner::Future(fut) => fut.poll(cx).map_err(Into::into),
|
||||
Inner::Error(e) => {
|
||||
InnerProj::Future(fut) => fut.poll(cx).map_err(Into::into),
|
||||
InnerProj::Error(e) => {
|
||||
let e = e.take().expect("Polled after ready.").into();
|
||||
Poll::Ready(Err(e))
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use super::{Policy, Retry};
|
||||
use futures_core::ready;
|
||||
use pin_project::{pin_project, project};
|
||||
use pin_project::pin_project;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
@ -23,7 +23,7 @@ where
|
|||
state: State<S::Future, P::Future>,
|
||||
}
|
||||
|
||||
#[pin_project]
|
||||
#[pin_project(project = StateProj)]
|
||||
#[derive(Debug)]
|
||||
enum State<F, P> {
|
||||
/// Polling the future from `Service::call`
|
||||
|
@ -59,14 +59,12 @@ where
|
|||
{
|
||||
type Output = Result<S::Response, S::Error>;
|
||||
|
||||
#[project]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let mut this = self.project();
|
||||
|
||||
loop {
|
||||
#[project]
|
||||
match this.state.as_mut().project() {
|
||||
State::Called(future) => {
|
||||
StateProj::Called(future) => {
|
||||
let result = ready!(future.poll(cx));
|
||||
if let Some(ref req) = this.request {
|
||||
match this.retry.policy.retry(req, result.as_ref()) {
|
||||
|
@ -80,7 +78,7 @@ where
|
|||
return Poll::Ready(result);
|
||||
}
|
||||
}
|
||||
State::Checking(future) => {
|
||||
StateProj::Checking(future) => {
|
||||
this.retry
|
||||
.as_mut()
|
||||
.project()
|
||||
|
@ -88,7 +86,7 @@ where
|
|||
.set(ready!(future.poll(cx)));
|
||||
this.state.set(State::Retrying);
|
||||
}
|
||||
State::Retrying => {
|
||||
StateProj::Retrying => {
|
||||
// NOTE: we assume here that
|
||||
//
|
||||
// this.retry.poll_ready()
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
//! See `Either` documentation for more details.
|
||||
|
||||
use futures_core::ready;
|
||||
use pin_project::{pin_project, project};
|
||||
use pin_project::pin_project;
|
||||
use std::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
|
@ -16,7 +16,7 @@ use tower_service::Service;
|
|||
/// Both services must be of the same request, response, and error types.
|
||||
/// `Either` is useful for handling conditional branching in service middleware
|
||||
/// to different inner service types.
|
||||
#[pin_project]
|
||||
#[pin_project(project = EitherProj)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Either<A, B> {
|
||||
/// One type of backing `Service`.
|
||||
|
@ -64,12 +64,10 @@ where
|
|||
{
|
||||
type Output = Result<T, crate::BoxError>;
|
||||
|
||||
#[project]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
#[project]
|
||||
match self.project() {
|
||||
Either::A(fut) => Poll::Ready(Ok(ready!(fut.poll(cx)).map_err(Into::into)?)),
|
||||
Either::B(fut) => Poll::Ready(Ok(ready!(fut.poll(cx)).map_err(Into::into)?)),
|
||||
EitherProj::A(fut) => Poll::Ready(Ok(ready!(fut.poll(cx)).map_err(Into::into)?)),
|
||||
EitherProj::B(fut) => Poll::Ready(Ok(ready!(fut.poll(cx)).map_err(Into::into)?)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use futures_core::ready;
|
||||
use pin_project::{pin_project, project};
|
||||
use pin_project::pin_project;
|
||||
use std::{
|
||||
fmt,
|
||||
future::Future,
|
||||
|
@ -18,7 +18,7 @@ pub struct Oneshot<S: Service<Req>, Req> {
|
|||
state: State<S, Req>,
|
||||
}
|
||||
|
||||
#[pin_project]
|
||||
#[pin_project(project = StateProj)]
|
||||
enum State<S: Service<Req>, Req> {
|
||||
NotReady(S, Option<Req>),
|
||||
Called(#[pin] S::Future),
|
||||
|
@ -62,23 +62,21 @@ where
|
|||
{
|
||||
type Output = Result<S::Response, S::Error>;
|
||||
|
||||
#[project]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let mut this = self.project();
|
||||
loop {
|
||||
#[project]
|
||||
match this.state.as_mut().project() {
|
||||
State::NotReady(svc, req) => {
|
||||
StateProj::NotReady(svc, req) => {
|
||||
let _ = ready!(svc.poll_ready(cx))?;
|
||||
let f = svc.call(req.take().expect("already called"));
|
||||
this.state.set(State::Called(f));
|
||||
}
|
||||
State::Called(fut) => {
|
||||
StateProj::Called(fut) => {
|
||||
let res = ready!(fut.poll(cx))?;
|
||||
this.state.set(State::Done);
|
||||
return Poll::Ready(Ok(res));
|
||||
}
|
||||
State::Done => panic!("polled after complete"),
|
||||
StateProj::Done => panic!("polled after complete"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue