Skip to content

Commit

Permalink
Add rc wrapped service RcService
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Jun 3, 2021
1 parent 8369e48 commit 3e480c0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ntex-service/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ntex-service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-service"
version = "0.1.8"
version = "0.1.9"
authors = ["ntex contributors <[email protected]>"]
description = "ntex service"
keywords = ["network", "framework", "async", "futures"]
Expand Down
20 changes: 19 additions & 1 deletion ntex-service/src/boxed.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -13,6 +13,15 @@ pub type BoxService<Req, Res, Err> = Box<
>,
>;

pub type RcService<Req, Res, Err> = Rc<
dyn Service<
Request = Req,
Response = Res,
Error = Err,
Future = BoxFuture<Res, Err>,
>,
>;

pub struct BoxServiceFactory<C, Req, Res, Err, InitErr>(
Inner<C, Req, Res, Err, InitErr>,
);
Expand Down Expand Up @@ -45,6 +54,15 @@ where
Box::new(ServiceWrapper(service))
}

/// Create rc service
pub fn rcservice<T>(service: T) -> RcService<T::Request, T::Response, T::Error>
where
T: Service + 'static,
T::Future: 'static,
{
Rc::new(ServiceWrapper(service))
}

type Inner<C, Req, Res, Err, InitErr> = Box<
dyn ServiceFactory<
Config = C,
Expand Down
2 changes: 1 addition & 1 deletion ntex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 3e480c0

Please sign in to comment.