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 | 53 ++++++++++++++++++++++++++++------------ 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/actix-utils/CHANGES.md b/actix-utils/CHANGES.md index a28ef8b4..8d971113 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 a69de3ca..cceb7339 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 56cfbdde..0de432db 100644 --- a/actix-utils/src/boxed.rs +++ b/actix-utils/src/boxed.rs @@ -10,7 +10,27 @@ pub type BoxedService = Box< >, >; -pub type BoxedNewService = Box< +/// Create boxed new service +pub fn new_service( + service: T, +) -> BoxedNewService +where + T: NewService + 'static, + T::Service: 'static, +{ + BoxedNewService(Box::new(NewServiceWrapper(service))) +} + +/// Create boxed service +pub fn service(service: T) -> BoxedService +where + T: Service + 'static, + T::Future: 'static, +{ + Box::new(ServiceWrapper(service)) +} + +type Inner = Box< NewService< Request = Req, Response = Res, @@ -21,24 +41,25 @@ pub type BoxedNewService = Box< >, >; -/// Create boxed new service -pub fn new_service( - service: T, -) -> BoxedNewService -where - T: NewService + 'static, - T::Service: 'static, -{ - Box::new(NewServiceWrapper(service)) -} +pub struct BoxedNewService(Inner); -/// Create boxed service -pub fn service(service: T) -> BoxedService +impl NewService for BoxedNewService where - T: Service + 'static, - T::Future: 'static, + Req: 'static, + Res: 'static, + Err: 'static, + InitErr: 'static, { - Box::new(ServiceWrapper(service)) + 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);