diff --git a/actix-connect/src/connector.rs b/actix-connect/src/connector.rs index e4c86d91..d3ef9813 100644 --- a/actix-connect/src/connector.rs +++ b/actix-connect/src/connector.rs @@ -75,9 +75,7 @@ impl Service> for TcpConnector { #[allow(clippy::type_complexity)] type Future = Either, Ready>>; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + actix_service::always_ready!(); fn call(&mut self, req: Connect) -> Self::Future { let port = req.port(); diff --git a/actix-connect/src/resolve.rs b/actix-connect/src/resolve.rs index 85edf0d8..2c75cc0d 100644 --- a/actix-connect/src/resolve.rs +++ b/actix-connect/src/resolve.rs @@ -110,9 +110,7 @@ impl Service> for Resolver { Ready, Self::Error>>, >; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + actix_service::always_ready!(); fn call(&mut self, mut req: Connect) -> Self::Future { if req.addr.is_some() { diff --git a/actix-connect/src/service.rs b/actix-connect/src/service.rs index ef5d04da..b942d230 100644 --- a/actix-connect/src/service.rs +++ b/actix-connect/src/service.rs @@ -94,9 +94,7 @@ impl Service> for ConnectService { type Error = ConnectError; type Future = ConnectServiceResponse; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + actix_service::always_ready!(); fn call(&mut self, req: Connect) -> Self::Future { ConnectServiceResponse { @@ -163,9 +161,7 @@ impl Service> for TcpConnectService { type Error = ConnectError; type Future = TcpConnectServiceResponse; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + actix_service::always_ready!(); fn call(&mut self, req: Connect) -> Self::Future { TcpConnectServiceResponse { diff --git a/actix-connect/src/ssl/openssl.rs b/actix-connect/src/ssl/openssl.rs index e1c6b6fb..a9bcc3c7 100644 --- a/actix-connect/src/ssl/openssl.rs +++ b/actix-connect/src/ssl/openssl.rs @@ -100,9 +100,7 @@ where #[allow(clippy::type_complexity)] type Future = Either, Ready>>; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + actix_service::always_ready!(); fn call(&mut self, stream: Connection) -> Self::Future { trace!("SSL Handshake start for: {:?}", stream.host()); @@ -220,9 +218,7 @@ impl Service for OpensslConnectService { type Error = ConnectError; type Future = OpensslConnectServiceResponse; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + actix_service::always_ready!(); fn call(&mut self, req: Connect) -> Self::Future { OpensslConnectServiceResponse { diff --git a/actix-connect/src/ssl/rustls.rs b/actix-connect/src/ssl/rustls.rs index 3e646082..984fbe49 100644 --- a/actix-connect/src/ssl/rustls.rs +++ b/actix-connect/src/ssl/rustls.rs @@ -96,9 +96,7 @@ where type Error = std::io::Error; type Future = ConnectAsyncExt; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + actix_service::always_ready!(); fn call(&mut self, stream: Connection) -> Self::Future { trace!("SSL Handshake start for: {:?}", stream.host()); diff --git a/actix-service/src/and_then_apply_fn.rs b/actix-service/src/and_then_apply_fn.rs index c7bd098c..01585e62 100644 --- a/actix-service/src/and_then_apply_fn.rs +++ b/actix-service/src/and_then_apply_fn.rs @@ -294,9 +294,7 @@ mod tests { type Error = (); type Future = Ready>; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + crate::always_ready!(); fn call(&mut self, req: u8) -> Self::Future { let _ = req; diff --git a/actix-service/src/apply.rs b/actix-service/src/apply.rs index 27a09684..ea788706 100644 --- a/actix-service/src/apply.rs +++ b/actix-service/src/apply.rs @@ -209,7 +209,7 @@ where #[cfg(test)] mod tests { - use std::task::{Context, Poll}; + use std::task::Poll; use futures_util::future::{lazy, ok, Ready}; @@ -224,9 +224,7 @@ mod tests { type Error = (); type Future = Ready>; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + crate::always_ready!(); fn call(&mut self, _: ()) -> Self::Future { ok(()) diff --git a/actix-service/src/boxed.rs b/actix-service/src/boxed.rs index 35a10dac..5d83360d 100644 --- a/actix-service/src/boxed.rs +++ b/actix-service/src/boxed.rs @@ -75,12 +75,9 @@ where } } -struct FactoryWrapper -where - SF: ServiceFactory, -{ +struct FactoryWrapper { factory: SF, - _t: PhantomData<(C, Req)>, + _t: PhantomData<(Req, Cfg)>, } impl ServiceFactory for FactoryWrapper diff --git a/actix-service/src/fn_service.rs b/actix-service/src/fn_service.rs index 7d15304d..232bf988 100644 --- a/actix-service/src/fn_service.rs +++ b/actix-service/src/fn_service.rs @@ -1,6 +1,6 @@ use std::future::Future; use std::marker::PhantomData; -use std::task::{Context, Poll}; +use std::task::Poll; use futures_util::future::{ok, Ready}; @@ -143,9 +143,7 @@ where type Error = Err; type Future = Fut; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + crate::always_ready!(); fn call(&mut self, req: Req) -> Self::Future { (self.f)(req) @@ -200,9 +198,7 @@ where type Error = Err; type Future = Fut; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + crate::always_ready!(); fn call(&mut self, req: Req) -> Self::Future { (self.f)(req) diff --git a/actix-service/src/lib.rs b/actix-service/src/lib.rs index 2dfa0dd7..df0ab2b8 100644 --- a/actix-service/src/lib.rs +++ b/actix-service/src/lib.rs @@ -359,3 +359,15 @@ pub mod dev { pub use crate::transform::ApplyTransform; pub use crate::transform_err::TransformMapInitErr; } + +#[macro_export] +macro_rules! always_ready { + () => { + fn poll_ready( + &mut self, + _: &mut ::std::task::Context<'_>, + ) -> ::std::task::Poll> { + Poll::Ready(Ok(())) + } + }; +} diff --git a/actix-service/src/map.rs b/actix-service/src/map.rs index 04ef8c5f..1460c065 100644 --- a/actix-service/src/map.rs +++ b/actix-service/src/map.rs @@ -207,9 +207,7 @@ mod tests { type Error = (); type Future = Ready>; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + crate::always_ready!(); fn call(&mut self, _: ()) -> Self::Future { ok(()) diff --git a/actix-utils/src/timeout.rs b/actix-utils/src/timeout.rs index 17647206..a27e9ffb 100644 --- a/actix-utils/src/timeout.rs +++ b/actix-utils/src/timeout.rs @@ -201,7 +201,7 @@ where #[cfg(test)] mod tests { - use std::task::{Context, Poll}; + use std::task::Poll; use std::time::Duration; use super::*; @@ -215,9 +215,7 @@ mod tests { type Error = (); type Future = LocalBoxFuture<'static, Result<(), ()>>; - fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } + actix_service::always_ready!(); fn call(&mut self, _: ()) -> Self::Future { actix_rt::time::delay_for(self.0)