From ed832bd008ab6855eaf5258ae0703ad99500901a Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 25 Dec 2021 02:09:09 +0000 Subject: [PATCH] ClientResponse does not require Unpin --- awc/CHANGES.md | 1 - awc/src/responses/response.rs | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/awc/CHANGES.md b/awc/CHANGES.md index af0b3de16..e1a059481 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -8,7 +8,6 @@ - `impl Future` for `ResponseBody` no longer requires the body type be `Unpin`. [#2546] - `impl Future` for `JsonBody` no longer requires the body type be `Unpin`. [#2546] - `impl Stream` for `ClientResponse` no longer requires the body type be `Unpin`. [#2546] -- `ClientResponse` is no longer `Unpin`. [#2546] [#2503]: https://github.com/actix/actix-web/pull/2503 [#2546]: https://github.com/actix/actix-web/pull/2546 diff --git a/awc/src/responses/response.rs b/awc/src/responses/response.rs index 2f535cbe9..6385aea19 100644 --- a/awc/src/responses/response.rs +++ b/awc/src/responses/response.rs @@ -13,6 +13,7 @@ use actix_http::{ use actix_rt::time::{sleep, Sleep}; use bytes::Bytes; use futures_core::Stream; +use pin_project_lite::pin_project; use serde::de::DeserializeOwned; #[cfg(feature = "cookies")] @@ -20,11 +21,14 @@ use crate::cookie::{Cookie, ParseError as CookieParseError}; use super::{JsonBody, ResponseBody, ResponseTimeout}; -/// Client Response -pub struct ClientResponse { - pub(crate) head: ResponseHead, - pub(crate) payload: Payload, - pub(crate) timeout: ResponseTimeout, +pin_project! { + /// Client Response + pub struct ClientResponse { + pub(crate) head: ResponseHead, + #[pin] + pub(crate) payload: Payload, + pub(crate) timeout: ResponseTimeout, + } } impl ClientResponse { @@ -234,10 +238,9 @@ where type Item = Result; fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - let this = self.get_mut(); + let this = self.project(); this.timeout.poll_timeout(cx)?; - - Pin::new(&mut this.payload).poll_next(cx) + this.payload.poll_next(cx) } } @@ -246,6 +249,9 @@ mod tests { use static_assertions::assert_impl_all; use super::*; + use crate::any_body::AnyBody; assert_impl_all!(ClientResponse: Unpin); + assert_impl_all!(ClientResponse<()>: Unpin); + assert_impl_all!(ClientResponse: Unpin); }