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