diff --git a/ntex-service/CHANGES.md b/ntex-service/CHANGES.md index 42ee6ba6a..973c52928 100644 --- a/ntex-service/CHANGES.md +++ b/ntex-service/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.1.9] - 2021-06-03 + +* Add rc wrapped service, `RcService` + ## [0.1.8] - 2021-04-11 * Move utils to ntex-util crate diff --git a/ntex-service/Cargo.toml b/ntex-service/Cargo.toml index 907567875..bbc5f9abb 100644 --- a/ntex-service/Cargo.toml +++ b/ntex-service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-service" -version = "0.1.8" +version = "0.1.9" authors = ["ntex contributors "] description = "ntex service" keywords = ["network", "framework", "async", "futures"] diff --git a/ntex-service/src/boxed.rs b/ntex-service/src/boxed.rs index 4d5b14f2c..50f07cd79 100644 --- a/ntex-service/src/boxed.rs +++ b/ntex-service/src/boxed.rs @@ -1,4 +1,4 @@ -use std::{future::Future, pin::Pin, task::Context, task::Poll}; +use std::{future::Future, pin::Pin, rc::Rc, task::Context, task::Poll}; use crate::{Service, ServiceFactory}; @@ -13,6 +13,15 @@ pub type BoxService = Box< >, >; +pub type RcService = Rc< + dyn Service< + Request = Req, + Response = Res, + Error = Err, + Future = BoxFuture, + >, +>; + pub struct BoxServiceFactory( Inner, ); @@ -45,6 +54,15 @@ where Box::new(ServiceWrapper(service)) } +/// Create rc service +pub fn rcservice(service: T) -> RcService +where + T: Service + 'static, + T::Future: 'static, +{ + Rc::new(ServiceWrapper(service)) +} + type Inner = Box< dyn ServiceFactory< Config = C, diff --git a/ntex/Cargo.toml b/ntex/Cargo.toml index 8879f9fa2..e365c0253 100644 --- a/ntex/Cargo.toml +++ b/ntex/Cargo.toml @@ -46,7 +46,7 @@ http-framework = ["h2", "http", "httparse", ntex-codec = "0.4.1" ntex-rt = "0.2.2" ntex-router = "0.4.2" -ntex-service = "0.1.8" +ntex-service = "0.1.9" ntex-macros = "0.1.3" ntex-util = "0.1.1"