ClientResponse does not require Unpin

This commit is contained in:
Rob Ede 2021-12-25 02:09:09 +00:00
parent ca2595bf44
commit ed832bd008
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
2 changed files with 14 additions and 9 deletions

View File

@ -8,7 +8,6 @@
- `impl Future` for `ResponseBody` no longer requires the body type be `Unpin`. [#2546] - `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 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] - `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 [#2503]: https://github.com/actix/actix-web/pull/2503
[#2546]: https://github.com/actix/actix-web/pull/2546 [#2546]: https://github.com/actix/actix-web/pull/2546

View File

@ -13,6 +13,7 @@ use actix_http::{
use actix_rt::time::{sleep, Sleep}; use actix_rt::time::{sleep, Sleep};
use bytes::Bytes; use bytes::Bytes;
use futures_core::Stream; use futures_core::Stream;
use pin_project_lite::pin_project;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
#[cfg(feature = "cookies")] #[cfg(feature = "cookies")]
@ -20,11 +21,14 @@ use crate::cookie::{Cookie, ParseError as CookieParseError};
use super::{JsonBody, ResponseBody, ResponseTimeout}; use super::{JsonBody, ResponseBody, ResponseTimeout};
/// Client Response pin_project! {
pub struct ClientResponse<S = BoxedPayloadStream> { /// Client Response
pub(crate) head: ResponseHead, pub struct ClientResponse<S = BoxedPayloadStream> {
pub(crate) payload: Payload<S>, pub(crate) head: ResponseHead,
pub(crate) timeout: ResponseTimeout, #[pin]
pub(crate) payload: Payload<S>,
pub(crate) timeout: ResponseTimeout,
}
} }
impl<S> ClientResponse<S> { impl<S> ClientResponse<S> {
@ -234,10 +238,9 @@ where
type Item = Result<Bytes, PayloadError>; type Item = Result<Bytes, PayloadError>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.get_mut(); let this = self.project();
this.timeout.poll_timeout(cx)?; this.timeout.poll_timeout(cx)?;
this.payload.poll_next(cx)
Pin::new(&mut this.payload).poll_next(cx)
} }
} }
@ -246,6 +249,9 @@ mod tests {
use static_assertions::assert_impl_all; use static_assertions::assert_impl_all;
use super::*; use super::*;
use crate::any_body::AnyBody;
assert_impl_all!(ClientResponse: Unpin); assert_impl_all!(ClientResponse: Unpin);
assert_impl_all!(ClientResponse<()>: Unpin);
assert_impl_all!(ClientResponse<AnyBody>: Unpin);
} }