From 6e19dde3e7be1b87a7cf5ad12923476c91be4a79 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Fri, 25 Dec 2020 02:05:31 +0000 Subject: [PATCH] update other crates --- actix-connect/src/connector.rs | 6 ++--- actix-connect/src/lib.rs | 12 +++++----- actix-connect/src/resolve.rs | 6 ++--- actix-connect/src/service.rs | 17 ++++++-------- actix-server/src/config.rs | 28 +++++++++++----------- actix-server/src/service.rs | 31 +++++++++++++----------- actix-tracing/src/lib.rs | 33 ++++++++++---------------- actix-utils/Cargo.toml | 2 +- actix-utils/src/dispatcher.rs | 39 ++++++++++++++++++++---------- actix-utils/src/timeout.rs | 43 +++++++++++++++++++--------------- 10 files changed, 113 insertions(+), 104 deletions(-) diff --git a/actix-connect/src/connector.rs b/actix-connect/src/connector.rs index 9dc9a2ad..e4c86d91 100644 --- a/actix-connect/src/connector.rs +++ b/actix-connect/src/connector.rs @@ -40,8 +40,7 @@ impl Clone for TcpConnectorFactory { } } -impl ServiceFactory for TcpConnectorFactory { - type Request = Connect; +impl ServiceFactory> for TcpConnectorFactory { type Response = Connection; type Error = ConnectError; type Config = (); @@ -70,8 +69,7 @@ impl Clone for TcpConnector { } } -impl Service for TcpConnector { - type Request = Connect; +impl Service> for TcpConnector { type Response = Connection; type Error = ConnectError; #[allow(clippy::type_complexity)] diff --git a/actix-connect/src/lib.rs b/actix-connect/src/lib.rs index 36d0b98a..d2111d41 100644 --- a/actix-connect/src/lib.rs +++ b/actix-connect/src/lib.rs @@ -76,8 +76,8 @@ pub async fn start_default_resolver() -> Result { /// Create TCP connector service. pub fn new_connector( resolver: AsyncResolver, -) -> impl Service, Response = Connection, Error = ConnectError> - + Clone { +) -> impl Service, Response = Connection, Error = ConnectError> + Clone +{ pipeline(Resolver::new(resolver)).and_then(TcpConnector::new()) } @@ -85,8 +85,8 @@ pub fn new_connector( pub fn new_connector_factory( resolver: AsyncResolver, ) -> impl ServiceFactory< + Connect, Config = (), - Request = Connect, Response = Connection, Error = ConnectError, InitError = (), @@ -96,15 +96,15 @@ pub fn new_connector_factory( /// Create connector service with default parameters. pub fn default_connector( -) -> impl Service, Response = Connection, Error = ConnectError> - + Clone { +) -> impl Service, Response = Connection, Error = ConnectError> + Clone +{ pipeline(Resolver::default()).and_then(TcpConnector::new()) } /// Create connector service factory with default parameters. pub fn default_connector_factory() -> impl ServiceFactory< + Connect, Config = (), - Request = Connect, Response = Connection, Error = ConnectError, InitError = (), diff --git a/actix-connect/src/resolve.rs b/actix-connect/src/resolve.rs index bfb1482f..85edf0d8 100644 --- a/actix-connect/src/resolve.rs +++ b/actix-connect/src/resolve.rs @@ -54,8 +54,7 @@ impl Clone for ResolverFactory { } } -impl ServiceFactory for ResolverFactory { - type Request = Connect; +impl ServiceFactory> for ResolverFactory { type Response = Connect; type Error = ConnectError; type Config = (); @@ -102,8 +101,7 @@ impl Clone for Resolver { } } -impl Service for Resolver { - type Request = Connect; +impl Service> for Resolver { type Response = Connect; type Error = ConnectError; #[allow(clippy::type_complexity)] diff --git a/actix-connect/src/service.rs b/actix-connect/src/service.rs index 1047e3df..ef5d04da 100644 --- a/actix-connect/src/service.rs +++ b/actix-connect/src/service.rs @@ -70,8 +70,7 @@ impl Clone for ConnectServiceFactory { } } -impl ServiceFactory for ConnectServiceFactory { - type Request = Connect; +impl ServiceFactory> for ConnectServiceFactory { type Response = Connection; type Error = ConnectError; type Config = (); @@ -90,8 +89,7 @@ pub struct ConnectService { resolver: Resolver, } -impl Service for ConnectService { - type Request = Connect; +impl Service> for ConnectService { type Response = Connection; type Error = ConnectError; type Future = ConnectServiceResponse; @@ -109,8 +107,8 @@ impl Service for ConnectService { } enum ConnectState { - Resolve( as Service>::Future), - Connect( as Service>::Future), + Resolve( as Service>>::Future), + Connect( as Service>>::Future), } impl ConnectState { @@ -160,8 +158,7 @@ pub struct TcpConnectService { resolver: Resolver, } -impl Service for TcpConnectService { - type Request = Connect; +impl Service> for TcpConnectService { type Response = TcpStream; type Error = ConnectError; type Future = TcpConnectServiceResponse; @@ -179,8 +176,8 @@ impl Service for TcpConnectService { } enum TcpConnectState { - Resolve( as Service>::Future), - Connect( as Service>::Future), + Resolve( as Service>>::Future), + Connect( as Service>>::Future), } impl TcpConnectState { diff --git a/actix-server/src/config.rs b/actix-server/src/config.rs index 28996b9b..a1315a72 100644 --- a/actix-server/src/config.rs +++ b/actix-server/src/config.rs @@ -2,7 +2,10 @@ use std::collections::HashMap; use std::{fmt, io, net}; use actix_rt::net::TcpStream; -use actix_service as actix; +use actix_service::{ + fn_service, IntoServiceFactory as IntoBaseServiceFactory, + ServiceFactory as BaseServiceFactory, +}; use actix_utils::counter::CounterGuard; use futures_util::future::{ok, Future, FutureExt, LocalBoxFuture}; use log::error; @@ -141,12 +144,10 @@ impl InternalServiceFactory for ConfiguredService { let name = names.remove(&token).unwrap().0; res.push(( token, - Box::new(StreamService::new(actix::fn_service( - move |_: TcpStream| { - error!("Service {:?} is not configured", name); - ok::<_, ()>(()) - }, - ))), + Box::new(StreamService::new(fn_service(move |_: TcpStream| { + error!("Service {:?} is not configured", name); + ok::<_, ()>(()) + }))), )); }; } @@ -208,8 +209,8 @@ impl ServiceRuntime { /// *ServiceConfig::bind()* or *ServiceConfig::listen()* methods. pub fn service(&mut self, name: &str, service: F) where - F: actix::IntoServiceFactory, - T: actix::ServiceFactory + 'static, + F: IntoBaseServiceFactory, + T: BaseServiceFactory + 'static, T::Future: 'static, T::Service: 'static, T::InitError: fmt::Debug, @@ -237,8 +238,8 @@ impl ServiceRuntime { } type BoxedNewService = Box< - dyn actix::ServiceFactory< - Request = (Option, StdStream), + dyn BaseServiceFactory< + (Option, StdStream), Response = (), Error = (), InitError = (), @@ -252,15 +253,14 @@ struct ServiceFactory { inner: T, } -impl actix::ServiceFactory for ServiceFactory +impl BaseServiceFactory<(Option, StdStream)> for ServiceFactory where - T: actix::ServiceFactory, + T: BaseServiceFactory, T::Future: 'static, T::Service: 'static, T::Error: 'static, T::InitError: fmt::Debug + 'static, { - type Request = (Option, StdStream); type Response = (); type Error = (); type Config = (); diff --git a/actix-server/src/service.rs b/actix-server/src/service.rs index 4fc49586..569ce048 100644 --- a/actix-server/src/service.rs +++ b/actix-server/src/service.rs @@ -3,7 +3,7 @@ use std::net::SocketAddr; use std::task::{Context, Poll}; use actix_rt::spawn; -use actix_service::{self as actix, Service, ServiceFactory as ActixServiceFactory}; +use actix_service::{Service, ServiceFactory as BaseServiceFactory}; use actix_utils::counter::CounterGuard; use futures_util::future::{err, ok, LocalBoxFuture, Ready}; use futures_util::{FutureExt, TryFutureExt}; @@ -13,7 +13,7 @@ use super::Token; use crate::socket::{FromStream, StdStream}; pub trait ServiceFactory: Send + Clone + 'static { - type Factory: actix::ServiceFactory; + type Factory: BaseServiceFactory; fn create(&self) -> Self::Factory; } @@ -28,31 +28,34 @@ pub(crate) trait InternalServiceFactory: Send { pub(crate) type BoxedServerService = Box< dyn Service< - Request = (Option, StdStream), + (Option, StdStream), Response = (), Error = (), Future = Ready>, >, >; -pub(crate) struct StreamService { - service: T, +pub(crate) struct StreamService { + service: S, + _phantom: PhantomData, } -impl StreamService { - pub(crate) fn new(service: T) -> Self { - StreamService { service } +impl StreamService { + pub(crate) fn new(service: S) -> Self { + StreamService { + service, + _phantom: PhantomData, + } } } -impl Service for StreamService +impl Service<(Option, StdStream)> for StreamService where - T: Service, - T::Future: 'static, - T::Error: 'static, + S: Service, + S::Future: 'static, + S::Error: 'static, I: FromStream, { - type Request = (Option, StdStream); type Response = (); type Error = (); type Future = Ready>; @@ -144,7 +147,7 @@ where impl ServiceFactory for F where F: Fn() -> T + Send + Clone + 'static, - T: actix::ServiceFactory, + T: BaseServiceFactory, I: FromStream, { type Factory = T; diff --git a/actix-tracing/src/lib.rs b/actix-tracing/src/lib.rs index b61ffac8..ada61daa 100644 --- a/actix-tracing/src/lib.rs +++ b/actix-tracing/src/lib.rs @@ -27,12 +27,11 @@ impl TracingService { } } -impl Service for TracingService +impl Service for TracingService where - S: Service, - F: Fn(&S::Request) -> Option, + S: Service, + F: Fn(&Req) -> Option, { - type Request = S::Request; type Response = S::Response; type Error = S::Error; type Future = Either>; @@ -41,7 +40,7 @@ where self.inner.poll_ready(ctx) } - fn call(&mut self, req: Self::Request) -> Self::Future { + fn call(&mut self, req: Req) -> Self::Future { let span = (self.make_span)(&req); let _enter = span.as_ref().map(|s| s.enter()); @@ -74,18 +73,12 @@ impl TracingTransform { } } -impl Transform for TracingTransform +impl Transform for TracingTransform where - S: Service, - U: ServiceFactory< - Request = S::Request, - Response = S::Response, - Error = S::Error, - Service = S, - >, - F: Fn(&S::Request) -> Option + Clone, + S: Service, + U: ServiceFactory, + F: Fn(&Req) -> Option + Clone, { - type Request = S::Request; type Response = S::Response; type Error = S::Error; type Transform = TracingService; @@ -110,14 +103,14 @@ where /// |req: &Request| Some(span!(Level::INFO, "request", req.id)) /// ); /// ``` -pub fn trace( +pub fn trace( service_factory: U, make_span: F, -) -> ApplyTransform, S> +) -> ApplyTransform, S, Req> where - S: ServiceFactory, - F: Fn(&S::Request) -> Option + Clone, - U: IntoServiceFactory, + S: ServiceFactory, + F: Fn(&Req) -> Option + Clone, + U: IntoServiceFactory, { apply( TracingTransform::new(make_span), diff --git a/actix-utils/Cargo.toml b/actix-utils/Cargo.toml index f5bd5793..fb7ed151 100644 --- a/actix-utils/Cargo.toml +++ b/actix-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-utils" -version = "3.0.0" +version = "2.0.0" authors = ["Nikolay Kim "] description = "Various network related services and utilities for the Actix ecosystem." keywords = ["network", "framework", "async", "futures"] diff --git a/actix-utils/src/dispatcher.rs b/actix-utils/src/dispatcher.rs index c3cb4f16..1e55aa2c 100644 --- a/actix-utils/src/dispatcher.rs +++ b/actix-utils/src/dispatcher.rs @@ -1,4 +1,4 @@ -//! Framed dispatcher service and related utilities +//! Framed dispatcher service and related utilities. #![allow(type_alias_bounds)] @@ -11,6 +11,7 @@ use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed}; use actix_service::{IntoService, Service}; use futures_core::stream::Stream; use log::debug; +use pin_project_lite::pin_project; use crate::mpsc; @@ -62,12 +63,12 @@ pub enum Message { Close, } -pin_project_lite::pin_project! { +pin_project! { /// Dispatcher is a future that reads frames from Framed object /// and passes them to the service. pub struct Dispatcher where - S: Service::Item, Response = I>, + S: Service<::Item, Response = I>, S::Error: 'static, S::Future: 'static, T: AsyncRead, @@ -86,7 +87,11 @@ pin_project_lite::pin_project! { } } -enum State + Decoder, I> { +enum State +where + S: Service<::Item>, + U: Encoder + Decoder, +{ Processing, Error(DispatcherError), FramedError(DispatcherError), @@ -94,7 +99,11 @@ enum State + Decoder, I> { Stopping, } -impl + Decoder, I> State { +impl State +where + S: Service<::Item>, + U: Encoder + Decoder, +{ fn take_error(&mut self) -> DispatcherError { match mem::replace(self, State::Processing) { State::Error(err) => err, @@ -112,7 +121,7 @@ impl + Decoder, I> State { impl Dispatcher where - S: Service::Item, Response = I>, + S: Service<::Item, Response = I>, S::Error: 'static, S::Future: 'static, T: AsyncRead + AsyncWrite, @@ -121,7 +130,10 @@ where ::Error: fmt::Debug, >::Error: fmt::Debug, { - pub fn new>(framed: Framed, service: F) -> Self { + pub fn new(framed: Framed, service: F) -> Self + where + F: IntoService::Item>, + { let (tx, rx) = mpsc::channel(); Dispatcher { framed, @@ -133,11 +145,14 @@ where } /// Construct new `Dispatcher` instance with customer `mpsc::Receiver` - pub fn with_rx>( + pub fn with_rx( framed: Framed, service: F, rx: mpsc::Receiver, S::Error>>, - ) -> Self { + ) -> Self + where + F: IntoService::Item>, + { let tx = rx.sender(); Dispatcher { framed, @@ -176,7 +191,7 @@ where fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> bool where - S: Service::Item, Response = I>, + S: Service<::Item, Response = I>, S::Error: 'static, S::Future: 'static, T: AsyncRead + AsyncWrite, @@ -220,7 +235,7 @@ where /// write to framed object fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> bool where - S: Service::Item, Response = I>, + S: Service<::Item, Response = I>, S::Error: 'static, S::Future: 'static, T: AsyncRead + AsyncWrite, @@ -271,7 +286,7 @@ where impl Future for Dispatcher where - S: Service::Item, Response = I>, + S: Service<::Item, Response = I>, S::Error: 'static, S::Future: 'static, T: AsyncRead + AsyncWrite, diff --git a/actix-utils/src/timeout.rs b/actix-utils/src/timeout.rs index f3489b85..d253d25d 100644 --- a/actix-utils/src/timeout.rs +++ b/actix-utils/src/timeout.rs @@ -2,6 +2,7 @@ //! //! If the response does not complete within the specified timeout, the response //! will be aborted. + use core::future::Future; use core::marker::PhantomData; use core::pin::Pin; @@ -10,6 +11,7 @@ use core::{fmt, time}; use actix_rt::time::{delay_for, Delay}; use actix_service::{IntoService, Service, Transform}; +use pin_project_lite::pin_project; /// Applies a timeout to requests. #[derive(Debug)] @@ -77,21 +79,21 @@ impl Clone for Timeout { } } -impl Transform for Timeout +impl Transform for Timeout where - S: Service, + S: Service, { - type Request = S::Request; type Response = S::Response; type Error = TimeoutError; - type Transform = TimeoutService; type InitError = E; + type Transform = TimeoutService; type Future = TimeoutFuture; fn new_transform(&self, service: S) -> Self::Future { let service = TimeoutService { service, timeout: self.timeout, + _phantom: PhantomData, }; TimeoutFuture { @@ -118,40 +120,41 @@ impl Future for TimeoutFuture { /// Applies a timeout to requests. #[derive(Debug, Clone)] -pub struct TimeoutService { +pub struct TimeoutService { service: S, timeout: time::Duration, + _phantom: PhantomData, } -impl TimeoutService +impl TimeoutService where - S: Service, + S: Service, { pub fn new(timeout: time::Duration, service: U) -> Self where - U: IntoService, + U: IntoService, { TimeoutService { timeout, service: service.into_service(), + _phantom: PhantomData, } } } -impl Service for TimeoutService +impl Service for TimeoutService where - S: Service, + S: Service, { - type Request = S::Request; type Response = S::Response; type Error = TimeoutError; - type Future = TimeoutServiceResponse; + type Future = TimeoutServiceResponse; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { self.service.poll_ready(cx).map_err(TimeoutError::Service) } - fn call(&mut self, request: S::Request) -> Self::Future { + fn call(&mut self, request: Req) -> Self::Future { TimeoutServiceResponse { fut: self.service.call(request), sleep: delay_for(self.timeout), @@ -159,19 +162,22 @@ where } } -pin_project_lite::pin_project! { +pin_project! { /// `TimeoutService` response future #[derive(Debug)] - pub struct TimeoutServiceResponse { + pub struct TimeoutServiceResponse + where + T: Service + { #[pin] fut: T::Future, sleep: Delay, } } -impl Future for TimeoutServiceResponse +impl Future for TimeoutServiceResponse where - T: Service, + T: Service, { type Output = Result>; @@ -204,8 +210,7 @@ mod tests { struct SleepService(Duration); - impl Service for SleepService { - type Request = (); + impl Service<()> for SleepService { type Response = (); type Error = (); type Future = LocalBoxFuture<'static, Result<(), ()>>;