Skip to content

Commit

Permalink
Custom BoxedNewService implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Feb 21, 2019
1 parent a97d7f0 commit 6ea128f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
7 changes: 7 additions & 0 deletions actix-utils/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changes

## [0.2.4] - 2019-02-21

### Changed

* Custom `BoxedNewService` implementation.


## [0.2.3] - 2019-02-21

### Added
Expand Down
8 changes: 4 additions & 4 deletions actix-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "actix-utils"
version = "0.2.3"
version = "0.2.4"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix utils - various actix net related services"
keywords = ["network", "framework", "async", "futures"]
Expand All @@ -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]
Expand Down
45 changes: 33 additions & 12 deletions actix-utils/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ pub type BoxedService<Req, Res, Err> = Box<
>,
>;

pub type BoxedNewService<Req, Res, Err, InitErr> = Box<
NewService<
Request = Req,
Response = Res,
Error = Err,
InitError = InitErr,
Service = BoxedService<Req, Res, Err>,
Future = Box<Future<Item = BoxedService<Req, Res, Err>, Error = InitErr>>,
>,
>;

/// Create boxed new service
pub fn new_service<T>(
service: T,
Expand All @@ -29,7 +18,7 @@ where
T: NewService + 'static,
T::Service: 'static,
{
Box::new(NewServiceWrapper(service))
BoxedNewService(Box::new(NewServiceWrapper(service)))
}

/// Create boxed service
Expand All @@ -41,6 +30,38 @@ where
Box::new(ServiceWrapper(service))
}

type Inner<Req, Res, Err, InitErr> = Box<
NewService<
Request = Req,
Response = Res,
Error = Err,
InitError = InitErr,
Service = BoxedService<Req, Res, Err>,
Future = Box<Future<Item = BoxedService<Req, Res, Err>, Error = InitErr>>,
>,
>;

pub struct BoxedNewService<Req, Res, Err, InitErr>(Inner<Req, Res, Err, InitErr>);

impl<Req, Res, Err, InitErr> NewService for BoxedNewService<Req, Res, Err, InitErr>
where
Req: 'static,
Res: 'static,
Err: 'static,
InitErr: 'static,
{
type Request = Req;
type Response = Res;
type Error = Err;
type InitError = InitErr;
type Service = BoxedService<Req, Res, Err>;
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>;

fn new_service(&self) -> Self::Future {
self.0.new_service()
}
}

struct NewServiceWrapper<T: NewService>(T);

impl<T, Req, Res, Err, InitErr> NewService for NewServiceWrapper<T>
Expand Down

0 comments on commit 6ea128f

Please sign in to comment.