Skip to content

Commit 237b2ce

Browse files
refactor(lib): Remove useless uses of Pin (#2405)
1 parent 9956587 commit 237b2ce

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

src/client/dispatch.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,22 @@ impl<T, U> Clone for UnboundedSender<T, U> {
138138
}
139139
}
140140

141-
#[pin_project::pin_project(PinnedDrop)]
142141
pub(crate) struct Receiver<T, U> {
143-
#[pin]
144142
inner: mpsc::UnboundedReceiver<Envelope<T, U>>,
145143
taker: want::Taker,
146144
}
147145

148146
impl<T, U> Receiver<T, U> {
149-
pub(crate) fn poll_next(
150-
self: Pin<&mut Self>,
147+
pub(crate) fn poll_recv(
148+
&mut self,
151149
cx: &mut task::Context<'_>,
152150
) -> Poll<Option<(T, Callback<T, U>)>> {
153-
let mut this = self.project();
154-
match this.inner.poll_recv(cx) {
151+
match self.inner.poll_recv(cx) {
155152
Poll::Ready(item) => {
156153
Poll::Ready(item.map(|mut env| env.0.take().expect("envelope not dropped")))
157154
}
158155
Poll::Pending => {
159-
this.taker.want();
156+
self.taker.want();
160157
Poll::Pending
161158
}
162159
}
@@ -177,12 +174,11 @@ impl<T, U> Receiver<T, U> {
177174
}
178175
}
179176

180-
#[pin_project::pinned_drop]
181-
impl<T, U> PinnedDrop for Receiver<T, U> {
182-
fn drop(mut self: Pin<&mut Self>) {
177+
impl<T, U> Drop for Receiver<T, U> {
178+
fn drop(&mut self) {
183179
// Notify the giver about the closure first, before dropping
184180
// the mpsc::Receiver.
185-
self.as_mut().taker.cancel();
181+
self.taker.cancel();
186182
}
187183
}
188184

@@ -279,8 +275,8 @@ mod tests {
279275
impl<T, U> Future for Receiver<T, U> {
280276
type Output = Option<(T, Callback<T, U>)>;
281277

282-
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
283-
self.poll_next(cx)
278+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
279+
self.poll_recv(cx)
284280
}
285281
}
286282

src/proto/h1/dispatch.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ cfg_server! {
4444
}
4545

4646
cfg_client! {
47-
#[pin_project::pin_project]
4847
pub(crate) struct Client<B> {
4948
callback: Option<crate::client::dispatch::Callback<Request<B>, http::Response<Body>>>,
50-
#[pin]
5149
rx: ClientRx<B>,
5250
rx_closed: bool,
5351
}
@@ -557,12 +555,12 @@ cfg_client! {
557555
type RecvItem = crate::proto::ResponseHead;
558556

559557
fn poll_msg(
560-
self: Pin<&mut Self>,
558+
mut self: Pin<&mut Self>,
561559
cx: &mut task::Context<'_>,
562560
) -> Poll<Option<Result<(Self::PollItem, Self::PollBody), crate::common::Never>>> {
563-
let this = self.project();
564-
debug_assert!(!*this.rx_closed);
565-
match this.rx.poll_next(cx) {
561+
let mut this = self.as_mut();
562+
debug_assert!(!this.rx_closed);
563+
match this.rx.poll_recv(cx) {
566564
Poll::Ready(Some((req, mut cb))) => {
567565
// check that future hasn't been canceled already
568566
match cb.poll_canceled(cx) {
@@ -578,15 +576,15 @@ cfg_client! {
578576
headers: parts.headers,
579577
extensions: parts.extensions,
580578
};
581-
*this.callback = Some(cb);
579+
this.callback = Some(cb);
582580
Poll::Ready(Some(Ok((head, body))))
583581
}
584582
}
585583
}
586584
Poll::Ready(None) => {
587585
// user has dropped sender handle
588586
trace!("client tx closed");
589-
*this.rx_closed = true;
587+
this.rx_closed = true;
590588
Poll::Ready(None)
591589
}
592590
Poll::Pending => Poll::Pending,

src/proto/h2/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ where
213213
}
214214
};
215215

216-
match Pin::new(&mut self.req_rx).poll_next(cx) {
216+
match self.req_rx.poll_recv(cx) {
217217
Poll::Ready(Some((req, cb))) => {
218218
// check that future hasn't been canceled already
219219
if cb.is_canceled() {

0 commit comments

Comments
 (0)