From 6ea128fac5c948ca62d5e26665f0d0eb4b211216 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 21 Feb 2019 11:19:16 -0800 Subject: [PATCH] Custom BoxedNewService implementation --- actix-utils/CHANGES.md | 7 +++++++ actix-utils/Cargo.toml | 8 +++---- actix-utils/src/boxed.rs | 45 +++++++++++++++++++++++++++++----------- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/actix-utils/CHANGES.md b/actix-utils/CHANGES.md index a28ef8b48f..8d97111375 100644 --- a/actix-utils/CHANGES.md +++ b/actix-utils/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [0.2.4] - 2019-02-21 + +### Changed + +* Custom `BoxedNewService` implementation. + + ## [0.2.3] - 2019-02-21 ### Added diff --git a/actix-utils/Cargo.toml b/actix-utils/Cargo.toml index a69de3cae8..cceb7339b4 100644 --- a/actix-utils/Cargo.toml +++ b/actix-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-utils" -version = "0.2.3" +version = "0.2.4" authors = ["Nikolay Kim "] description = "Actix utils - various actix net related services" keywords = ["network", "framework", "async", "futures"] @@ -18,12 +18,12 @@ name = "actix_utils" path = "src/lib.rs" [dependencies] -actix-service = "0.2.1" +actix-service = "0.2.2" actix-codec = "0.1.0" bytes = "0.4" -futures = "0.1" +futures = "0.1.24" tokio-timer = "0.2.8" -tokio-current-thread = "0.1" +tokio-current-thread = "0.1.4" log = "0.4" [dev-dependencies] diff --git a/actix-utils/src/boxed.rs b/actix-utils/src/boxed.rs index 56cfbddec3..0de432db78 100644 --- a/actix-utils/src/boxed.rs +++ b/actix-utils/src/boxed.rs @@ -10,17 +10,6 @@ pub type BoxedService = Box< >, >; -pub type BoxedNewService = Box< - NewService< - Request = Req, - Response = Res, - Error = Err, - InitError = InitErr, - Service = BoxedService, - Future = Box, Error = InitErr>>, - >, ->; - /// Create boxed new service pub fn new_service( service: T, @@ -29,7 +18,7 @@ where T: NewService + 'static, T::Service: 'static, { - Box::new(NewServiceWrapper(service)) + BoxedNewService(Box::new(NewServiceWrapper(service))) } /// Create boxed service @@ -41,6 +30,38 @@ where Box::new(ServiceWrapper(service)) } +type Inner = Box< + NewService< + Request = Req, + Response = Res, + Error = Err, + InitError = InitErr, + Service = BoxedService, + Future = Box, Error = InitErr>>, + >, +>; + +pub struct BoxedNewService(Inner); + +impl NewService for BoxedNewService +where + Req: 'static, + Res: 'static, + Err: 'static, + InitErr: 'static, +{ + type Request = Req; + type Response = Res; + type Error = Err; + type InitError = InitErr; + type Service = BoxedService; + type Future = Box>; + + fn new_service(&self) -> Self::Future { + self.0.new_service() + } +} + struct NewServiceWrapper(T); impl NewService for NewServiceWrapper