Skip to content

Commit

Permalink
Remove uses of pin_project::project attribute
Browse files Browse the repository at this point in the history
pin-project will deprecate the project attribute due to some unfixable
limitations.

Refs: taiki-e/pin-project#225
  • Loading branch information
taiki-e committed Jun 5, 2020
1 parent bb49a92 commit bdf2e89
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tower-service = "0.3"
# tls is enabled by default, we don't want that yet
tokio-tungstenite = { version = "0.10", default-features = false, optional = true }
urlencoding = "1.0.0"
pin-project = "0.4.5"
pin-project = "0.4.17"
tokio-rustls = { version = "0.13.1", optional = true }

[dev-dependencies]
Expand Down
12 changes: 5 additions & 7 deletions src/filter/and.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::pin::Pin;
use std::task::{Context, Poll};

use futures::ready;
use pin_project::{pin_project, project};
use pin_project::pin_project;

use super::{Combine, Filter, FilterBase, HList, Internal, Tuple};
use crate::reject::CombineRejection;
Expand Down Expand Up @@ -41,7 +41,7 @@ pub struct AndFuture<T: Filter, U: Filter> {
state: State<T, U>,
}

#[pin_project]
#[pin_project(project = StateProj)]
enum State<T: Filter, U: Filter> {
First(#[pin] T::Future, U),
Second(Option<T::Extract>, #[pin] U::Future),
Expand All @@ -59,17 +59,15 @@ where
<<<T::Extract as Tuple>::HList as Combine<<U::Extract as Tuple>::HList>>::Output as HList>::Tuple,
<U::Error as CombineRejection<T::Error>>::One>;

#[project]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
loop {
let pin = self.as_mut().project();
#[project]
let (ex1, fut2) = match pin.state.project() {
State::First(first, second) => match ready!(first.poll(cx)) {
StateProj::First(first, second) => match ready!(first.poll(cx)) {
Ok(first) => (first, second.filter(Internal)),
Err(err) => return Poll::Ready(Err(From::from(err))),
},
State::Second(ex1, second) => {
StateProj::Second(ex1, second) => {
let ex2 = match ready!(second.poll(cx)) {
Ok(second) => second,
Err(err) => return Poll::Ready(Err(From::from(err))),
Expand All @@ -78,7 +76,7 @@ where
self.set(AndFuture { state: State::Done });
return Poll::Ready(Ok(ex3));
}
State::Done => panic!("polled after complete"),
StateProj::Done => panic!("polled after complete"),
};

self.set(AndFuture {
Expand Down
12 changes: 5 additions & 7 deletions src/filter/and_then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::pin::Pin;
use std::task::{Context, Poll};

use futures::{ready, TryFuture};
use pin_project::{pin_project, project};
use pin_project::pin_project;

use super::{Filter, FilterBase, Func, Internal};
use crate::reject::CombineRejection;
Expand Down Expand Up @@ -45,7 +45,7 @@ where
state: State<T, F>,
}

#[pin_project]
#[pin_project(project = StateProj)]
enum State<T, F>
where
T: Filter,
Expand All @@ -70,25 +70,23 @@ where
<<F::Output as TryFuture>::Error as CombineRejection<T::Error>>::One,
>;

#[project]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
loop {
let pin = self.as_mut().project();
#[project]
let (ex1, second) = match pin.state.project() {
State::First(first, second) => match ready!(first.try_poll(cx)) {
StateProj::First(first, second) => match ready!(first.try_poll(cx)) {
Ok(first) => (first, second),
Err(err) => return Poll::Ready(Err(From::from(err))),
},
State::Second(second) => {
StateProj::Second(second) => {
let ex3 = match ready!(second.try_poll(cx)) {
Ok(item) => Ok((item,)),
Err(err) => Err(From::from(err)),
};
self.set(AndThenFuture { state: State::Done });
return Poll::Ready(ex3);
}
State::Done => panic!("polled after complete"),
StateProj::Done => panic!("polled after complete"),
};
let fut2 = second.call(ex1);
self.set(AndThenFuture {
Expand Down
12 changes: 5 additions & 7 deletions src/filter/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::pin::Pin;
use std::task::{Context, Poll};

use futures::{ready, TryFuture};
use pin_project::{pin_project, project};
use pin_project::pin_project;

use super::{Filter, FilterBase, Internal};
use crate::generic::Either;
Expand Down Expand Up @@ -46,7 +46,7 @@ pub struct EitherFuture<T: Filter, U: Filter> {
original_path_index: PathIndex,
}

#[pin_project]
#[pin_project(project = StateProj)]
enum State<T: Filter, U: Filter> {
First(#[pin] T::Future, U),
Second(Option<T::Error>, #[pin] U::Future),
Expand All @@ -70,13 +70,11 @@ where
{
type Output = Result<(Either<T::Extract, U::Extract>,), Combined<U::Error, T::Error>>;

#[project]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
loop {
let pin = self.as_mut().project();
#[project]
let (err1, fut2) = match pin.state.project() {
State::First(first, second) => match ready!(first.try_poll(cx)) {
StateProj::First(first, second) => match ready!(first.try_poll(cx)) {
Ok(ex1) => {
return Poll::Ready(Ok((Either::A(ex1),)));
}
Expand All @@ -85,7 +83,7 @@ where
(e, second.filter(Internal))
}
},
State::Second(err1, second) => {
StateProj::Second(err1, second) => {
let ex2 = match ready!(second.try_poll(cx)) {
Ok(ex2) => Ok((Either::B(ex2),)),
Err(e) => {
Expand All @@ -100,7 +98,7 @@ where
});
return Poll::Ready(ex2);
}
State::Done => panic!("polled after complete"),
StateProj::Done => panic!("polled after complete"),
};

self.set(EitherFuture {
Expand Down
12 changes: 5 additions & 7 deletions src/filter/or_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::pin::Pin;
use std::task::{Context, Poll};

use futures::{ready, TryFuture};
use pin_project::{pin_project, project};
use pin_project::pin_project;

use super::{Filter, FilterBase, Func, Internal};
use crate::reject::IsReject;
Expand Down Expand Up @@ -48,7 +48,7 @@ where
original_path_index: PathIndex,
}

#[pin_project]
#[pin_project(project = StateProj)]
enum State<T, F>
where
T: Filter,
Expand Down Expand Up @@ -77,25 +77,23 @@ where
{
type Output = Result<<F::Output as TryFuture>::Ok, <F::Output as TryFuture>::Error>;

#[project]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
loop {
let pin = self.as_mut().project();
#[project]
let (err, second) = match pin.state.project() {
State::First(first, second) => match ready!(first.try_poll(cx)) {
StateProj::First(first, second) => match ready!(first.try_poll(cx)) {
Ok(ex) => return Poll::Ready(Ok(ex)),
Err(err) => (err, second),
},
State::Second(second) => {
StateProj::Second(second) => {
let ex2 = ready!(second.try_poll(cx));
self.set(OrElseFuture {
state: State::Done,
..*self
});
return Poll::Ready(ex2);
}
State::Done => panic!("polled after complete"),
StateProj::Done => panic!("polled after complete"),
};

pin.original_path_index.reset_path();
Expand Down
12 changes: 5 additions & 7 deletions src/filter/recover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::pin::Pin;
use std::task::{Context, Poll};

use futures::{ready, TryFuture};
use pin_project::{pin_project, project};
use pin_project::pin_project;

use super::{Filter, FilterBase, Func, Internal};
use crate::generic::Either;
Expand Down Expand Up @@ -50,7 +50,7 @@ where
original_path_index: PathIndex,
}

#[pin_project]
#[pin_project(project = StateProj)]
enum State<T, F>
where
T: Filter,
Expand Down Expand Up @@ -84,17 +84,15 @@ where
<F::Output as TryFuture>::Error,
>;

#[project]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
loop {
let pin = self.as_mut().project();
#[project]
let (err, second) = match pin.state.project() {
State::First(first, second) => match ready!(first.try_poll(cx)) {
StateProj::First(first, second) => match ready!(first.try_poll(cx)) {
Ok(ex) => return Poll::Ready(Ok((Either::A(ex),))),
Err(err) => (err, second),
},
State::Second(second) => {
StateProj::Second(second) => {
let ex2 = match ready!(second.try_poll(cx)) {
Ok(ex2) => Ok((Either::B((ex2,)),)),
Err(e) => Err(e),
Expand All @@ -105,7 +103,7 @@ where
});
return Poll::Ready(ex2);
}
State::Done => panic!("polled after complete"),
StateProj::Done => panic!("polled after complete"),
};

pin.original_path_index.reset_path();
Expand Down

0 comments on commit bdf2e89

Please sign in to comment.