diff --git a/Cargo.toml b/Cargo.toml index 4c3b11e2..8c6d461d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,7 +90,7 @@ fxhash = "0.2.1" log = "0.4" mime = "0.3" socket2 = "0.3" -pin-project = "0.4.6" +pin-project = "0.4.17" regex = "1.3" serde = { version = "1.0", features=["derive"] } serde_json = "1.0" diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index edd8201d..d2ae7698 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -70,7 +70,7 @@ language-tags = "0.2" log = "0.4" mime = "0.3" percent-encoding = "2.1" -pin-project = "0.4.6" +pin-project = "0.4.17" rand = "0.7" regex = "1.3" serde = "1.0" diff --git a/actix-http/src/body.rs b/actix-http/src/body.rs index 9d6fb26e..0b01aa8c 100644 --- a/actix-http/src/body.rs +++ b/actix-http/src/body.rs @@ -6,7 +6,7 @@ use std::{fmt, mem}; use bytes::{Bytes, BytesMut}; use futures_core::Stream; use futures_util::ready; -use pin_project::{pin_project, project}; +use pin_project::pin_project; use crate::error::Error; @@ -70,7 +70,7 @@ impl MessageBody for Box { } } -#[pin_project] +#[pin_project(project = ResponseBodyProj)] pub enum ResponseBody { Body(#[pin] B), Other(#[pin] Body), @@ -109,15 +109,13 @@ impl MessageBody for ResponseBody { } } - #[project] fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll>> { - #[project] match self.project() { - ResponseBody::Body(body) => body.poll_next(cx), - ResponseBody::Other(body) => body.poll_next(cx), + ResponseBodyProj::Body(body) => body.poll_next(cx), + ResponseBodyProj::Other(body) => body.poll_next(cx), } } } @@ -125,20 +123,18 @@ impl MessageBody for ResponseBody { impl Stream for ResponseBody { type Item = Result; - #[project] fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll> { - #[project] match self.project() { - ResponseBody::Body(body) => body.poll_next(cx), - ResponseBody::Other(body) => body.poll_next(cx), + ResponseBodyProj::Body(body) => body.poll_next(cx), + ResponseBodyProj::Other(body) => body.poll_next(cx), } } } -#[pin_project] +#[pin_project(project = BodyProj)] /// Represents various types of http message body. pub enum Body { /// Empty response. `Content-Length` header is not set. @@ -173,16 +169,14 @@ impl MessageBody for Body { } } - #[project] fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll>> { - #[project] match self.project() { - Body::None => Poll::Ready(None), - Body::Empty => Poll::Ready(None), - Body::Bytes(ref mut bin) => { + BodyProj::None => Poll::Ready(None), + BodyProj::Empty => Poll::Ready(None), + BodyProj::Bytes(ref mut bin) => { let len = bin.len(); if len == 0 { Poll::Ready(None) @@ -190,7 +184,7 @@ impl MessageBody for Body { Poll::Ready(Some(Ok(mem::take(bin)))) } } - Body::Message(ref mut body) => Pin::new(body.as_mut()).poll_next(cx), + BodyProj::Message(ref mut body) => Pin::new(body.as_mut()).poll_next(cx), } } } diff --git a/actix-http/src/client/connection.rs b/actix-http/src/client/connection.rs index c1362df8..eecf2ee6 100644 --- a/actix-http/src/client/connection.rs +++ b/actix-http/src/client/connection.rs @@ -7,7 +7,7 @@ use actix_codec::{AsyncRead, AsyncWrite, Framed}; use bytes::{Buf, Bytes}; use futures_util::future::{err, Either, FutureExt, LocalBoxFuture, Ready}; use h2::client::SendRequest; -use pin_project::{pin_project, project}; +use pin_project::pin_project; use crate::body::MessageBody; use crate::h1::ClientCodec; @@ -205,7 +205,7 @@ where } } -#[pin_project] +#[pin_project(project = EitherIoProj)] pub enum EitherIo { A(#[pin] A), B(#[pin] B), @@ -216,16 +216,14 @@ where A: AsyncRead, B: AsyncRead, { - #[project] fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { - #[project] match self.project() { - EitherIo::A(val) => val.poll_read(cx, buf), - EitherIo::B(val) => val.poll_read(cx, buf), + EitherIoProj::A(val) => val.poll_read(cx, buf), + EitherIoProj::B(val) => val.poll_read(cx, buf), } } @@ -245,41 +243,34 @@ where A: AsyncWrite, B: AsyncWrite, { - #[project] fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { - #[project] match self.project() { - EitherIo::A(val) => val.poll_write(cx, buf), - EitherIo::B(val) => val.poll_write(cx, buf), + EitherIoProj::A(val) => val.poll_write(cx, buf), + EitherIoProj::B(val) => val.poll_write(cx, buf), } } - #[project] fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - #[project] match self.project() { - EitherIo::A(val) => val.poll_flush(cx), - EitherIo::B(val) => val.poll_flush(cx), + EitherIoProj::A(val) => val.poll_flush(cx), + EitherIoProj::B(val) => val.poll_flush(cx), } } - #[project] fn poll_shutdown( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll> { - #[project] match self.project() { - EitherIo::A(val) => val.poll_shutdown(cx), - EitherIo::B(val) => val.poll_shutdown(cx), + EitherIoProj::A(val) => val.poll_shutdown(cx), + EitherIoProj::B(val) => val.poll_shutdown(cx), } } - #[project] fn poll_write_buf( self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -288,10 +279,9 @@ where where Self: Sized, { - #[project] match self.project() { - EitherIo::A(val) => val.poll_write_buf(cx, buf), - EitherIo::B(val) => val.poll_write_buf(cx, buf), + EitherIoProj::A(val) => val.poll_write_buf(cx, buf), + EitherIoProj::B(val) => val.poll_write_buf(cx, buf), } } } diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs index ef69aa03..eb182128 100644 --- a/actix-http/src/encoding/encoder.rs +++ b/actix-http/src/encoding/encoder.rs @@ -9,7 +9,7 @@ use brotli2::write::BrotliEncoder; use bytes::Bytes; use flate2::write::{GzEncoder, ZlibEncoder}; use futures_core::ready; -use pin_project::{pin_project, project}; +use pin_project::pin_project; use crate::body::{Body, BodySize, MessageBody, ResponseBody}; use crate::http::header::{ContentEncoding, CONTENT_ENCODING}; @@ -79,7 +79,7 @@ impl Encoder { } } -#[pin_project] +#[pin_project(project = EncoderBodyProj)] enum EncoderBody { Bytes(Bytes), Stream(#[pin] B), @@ -95,22 +95,22 @@ impl MessageBody for EncoderBody { } } - #[project] fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll>> { - #[project] match self.project() { - EncoderBody::Bytes(b) => { + EncoderBodyProj::Bytes(b) => { if b.is_empty() { Poll::Ready(None) } else { Poll::Ready(Some(Ok(std::mem::take(b)))) } } - EncoderBody::Stream(b) => b.poll_next(cx), - EncoderBody::BoxedStream(ref mut b) => Pin::new(b.as_mut()).poll_next(cx), + EncoderBodyProj::Stream(b) => b.poll_next(cx), + EncoderBodyProj::BoxedStream(ref mut b) => { + Pin::new(b.as_mut()).poll_next(cx) + } } } } diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index c95000bf..e16d3536 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -58,7 +58,7 @@ where inner: DispatcherState, } -#[pin_project] +#[pin_project(project = DispatcherStateProj)] enum DispatcherState where S: Service, @@ -73,7 +73,7 @@ where Upgrade(Pin>), } -#[pin_project] +#[pin_project(project = InnerDispatcherProj)] struct InnerDispatcher where S: Service, @@ -112,7 +112,7 @@ enum DispatcherMessage { Error(Response<()>), } -#[pin_project] +#[pin_project(project = StateProj)] enum State where S: Service, @@ -296,7 +296,6 @@ where /// /// true - got WouldBlock /// false - didn't get WouldBlock - #[pin_project::project] fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -307,8 +306,7 @@ where let len = self.write_buf.len(); let mut written = 0; - #[project] - let InnerDispatcher { io, write_buf, .. } = self.project(); + let InnerDispatcherProj { io, write_buf, .. } = self.project(); let mut io = Pin::new(io.as_mut().unwrap()); while written < len { match io.as_mut().poll_write(cx, &write_buf[written..]) { @@ -366,16 +364,14 @@ where .extend_from_slice(b"HTTP/1.1 100 Continue\r\n\r\n"); } - #[pin_project::project] fn poll_response( mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Result { loop { let mut this = self.as_mut().project(); - #[project] let state = match this.state.project() { - State::None => match this.messages.pop_front() { + StateProj::None => match this.messages.pop_front() { Some(DispatcherMessage::Item(req)) => { Some(self.as_mut().handle_request(req, cx)?) } @@ -388,7 +384,7 @@ where } None => None, }, - State::ExpectCall(fut) => match fut.as_mut().poll(cx) { + StateProj::ExpectCall(fut) => match fut.as_mut().poll(cx) { Poll::Ready(Ok(req)) => { self.as_mut().send_continue(); this = self.as_mut().project(); @@ -403,7 +399,7 @@ where } Poll::Pending => None, }, - State::ServiceCall(fut) => match fut.as_mut().poll(cx) { + StateProj::ServiceCall(fut) => match fut.as_mut().poll(cx) { Poll::Ready(Ok(res)) => { let (res, body) = res.into().replace_body(()); let state = self.as_mut().send_response(res, body)?; @@ -418,7 +414,7 @@ where } Poll::Pending => None, }, - State::SendPayload(mut stream) => { + StateProj::SendPayload(mut stream) => { loop { if this.write_buf.len() < HW_BUFFER_SIZE { match stream.as_mut().poll_next(cx) { @@ -724,13 +720,11 @@ where { type Output = Result<(), DispatchError>; - #[pin_project::project] #[inline] fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let this = self.as_mut().project(); - #[project] match this.inner.project() { - DispatcherState::Normal(mut inner) => { + DispatcherStateProj::Normal(mut inner) => { inner.as_mut().poll_keepalive(cx)?; if inner.flags.contains(Flags::SHUTDOWN) { @@ -850,7 +844,7 @@ where } } } - DispatcherState::Upgrade(fut) => fut.as_mut().poll(cx).map_err(|e| { + DispatcherStateProj::Upgrade(fut) => fut.as_mut().poll(cx).map_err(|e| { error!("Upgrade handler error: {}", e); DispatchError::Upgrade }), diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index a189697a..33fb3a81 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -165,7 +165,7 @@ struct ServiceResponse { _t: PhantomData<(I, E)>, } -#[pin_project::pin_project] +#[pin_project::pin_project(project = ServiceResponseStateProj)] enum ServiceResponseState { ServiceCall(#[pin] F, Option>), SendPayload(SendStream, #[pin] ResponseBody), @@ -245,13 +245,11 @@ where { type Output = (); - #[pin_project::project] fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let mut this = self.as_mut().project(); - #[project] match this.state.project() { - ServiceResponseState::ServiceCall(call, send) => match call.poll(cx) { + ServiceResponseStateProj::ServiceCall(call, send) => match call.poll(cx) { Poll::Ready(Ok(res)) => { let (res, body) = res.into().replace_body(()); @@ -305,7 +303,7 @@ where } } }, - ServiceResponseState::SendPayload(ref mut stream, ref mut body) => loop { + ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => loop { loop { if let Some(ref mut buffer) = this.buffer { match stream.poll_capacity(cx) { diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index 51de9513..94cdbc82 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -10,7 +10,7 @@ use bytes::Bytes; use futures_core::{ready, Future}; use futures_util::future::ok; use h2::server::{self, Handshake}; -use pin_project::{pin_project, project}; +use pin_project::pin_project; use crate::body::MessageBody; use crate::builder::HttpServiceBuilder; @@ -574,7 +574,7 @@ where } } -#[pin_project] +#[pin_project(project = StateProj)] enum State where S: Service, @@ -650,16 +650,14 @@ where U: Service), Response = ()>, U::Error: fmt::Display, { - #[project] fn poll( mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll> { - #[project] match self.as_mut().project() { - State::H1(disp) => disp.poll(cx), - State::H2(disp) => disp.poll(cx), - State::H2Handshake(ref mut data) => { + StateProj::H1(disp) => disp.poll(cx), + StateProj::H2(disp) => disp.poll(cx), + StateProj::H2Handshake(ref mut data) => { let conn = if let Some(ref mut item) = data { match Pin::new(&mut item.0).poll(cx) { Poll::Ready(Ok(conn)) => conn, diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index 20fd3743..8db7a35e 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -23,7 +23,7 @@ actix-codec = "0.2.0" bytes = "0.5.2" futures-channel = { version = "0.3.5", default-features = false } futures-core = { version = "0.3.5", default-features = false } -pin-project = "0.4.6" +pin-project = "0.4.17" [dev-dependencies] actix-rt = "1.0.0" diff --git a/src/responder.rs b/src/responder.rs index 367c9fcc..e102d23e 100644 --- a/src/responder.rs +++ b/src/responder.rs @@ -12,7 +12,7 @@ use actix_http::{Error, Response, ResponseBuilder}; use bytes::{Bytes, BytesMut}; use futures_util::future::{err, ok, Either as EitherFuture, Ready}; use futures_util::ready; -use pin_project::{pin_project, project}; +use pin_project::pin_project; use crate::request::HttpRequest; @@ -379,7 +379,7 @@ where } } -#[pin_project] +#[pin_project(project = EitherResponderProj)] pub enum EitherResponder where A: Responder, @@ -396,14 +396,12 @@ where { type Output = Result; - #[project] fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - #[project] match self.project() { - EitherResponder::A(fut) => { + EitherResponderProj::A(fut) => { Poll::Ready(ready!(fut.poll(cx)).map_err(|e| e.into())) } - EitherResponder::B(fut) => { + EitherResponderProj::B(fut) => { Poll::Ready(ready!(fut.poll(cx).map_err(|e| e.into()))) } }