From 3030f83fa5879b0649fa8db90b61ebec1f872408 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sun, 17 Jan 2021 09:04:47 +0100 Subject: [PATCH] refactor(lib): Remove useless uses of Pin --- src/client/dispatch.rs | 22 +++++++++------------- src/proto/h1/dispatch.rs | 14 ++++++-------- src/proto/h2/client.rs | 2 +- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 804eebbfc2..17cfbf4f8c 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -138,25 +138,22 @@ impl Clone for UnboundedSender { } } -#[pin_project::pin_project(PinnedDrop)] pub(crate) struct Receiver { - #[pin] inner: mpsc::UnboundedReceiver>, taker: want::Taker, } impl Receiver { - pub(crate) fn poll_next( - self: Pin<&mut Self>, + pub(crate) fn poll_recv( + &mut self, cx: &mut task::Context<'_>, ) -> Poll)>> { - let mut this = self.project(); - match this.inner.poll_recv(cx) { + match self.inner.poll_recv(cx) { Poll::Ready(item) => { Poll::Ready(item.map(|mut env| env.0.take().expect("envelope not dropped"))) } Poll::Pending => { - this.taker.want(); + self.taker.want(); Poll::Pending } } @@ -177,12 +174,11 @@ impl Receiver { } } -#[pin_project::pinned_drop] -impl PinnedDrop for Receiver { - fn drop(mut self: Pin<&mut Self>) { +impl Drop for Receiver { + fn drop(&mut self) { // Notify the giver about the closure first, before dropping // the mpsc::Receiver. - self.as_mut().taker.cancel(); + self.taker.cancel(); } } @@ -279,8 +275,8 @@ mod tests { impl Future for Receiver { type Output = Option<(T, Callback)>; - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - self.poll_next(cx) + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + self.poll_recv(cx) } } diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index 39f457efa3..88e641e9a4 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -44,10 +44,8 @@ cfg_server! { } cfg_client! { - #[pin_project::pin_project] pub(crate) struct Client { callback: Option, http::Response>>, - #[pin] rx: ClientRx, rx_closed: bool, } @@ -557,12 +555,12 @@ cfg_client! { type RecvItem = crate::proto::ResponseHead; fn poll_msg( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, cx: &mut task::Context<'_>, ) -> Poll>> { - let this = self.project(); - debug_assert!(!*this.rx_closed); - match this.rx.poll_next(cx) { + let mut this = self.as_mut(); + debug_assert!(!this.rx_closed); + match this.rx.poll_recv(cx) { Poll::Ready(Some((req, mut cb))) => { // check that future hasn't been canceled already match cb.poll_canceled(cx) { @@ -578,7 +576,7 @@ cfg_client! { headers: parts.headers, extensions: parts.extensions, }; - *this.callback = Some(cb); + this.callback = Some(cb); Poll::Ready(Some(Ok((head, body)))) } } @@ -586,7 +584,7 @@ cfg_client! { Poll::Ready(None) => { // user has dropped sender handle trace!("client tx closed"); - *this.rx_closed = true; + this.rx_closed = true; Poll::Ready(None) } Poll::Pending => Poll::Pending, diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 3c837feb9c..4f583f2bfa 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -213,7 +213,7 @@ where } }; - match Pin::new(&mut self.req_rx).poll_next(cx) { + match self.req_rx.poll_recv(cx) { Poll::Ready(Some((req, cb))) => { // check that future hasn't been canceled already if cb.is_canceled() {