mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-18 11:51:50 +01:00
Custom BoxedNewService implementation
This commit is contained in:
parent
a97d7f0ccf
commit
6ea128fac5
@ -1,5 +1,12 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.4] - 2019-02-21
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Custom `BoxedNewService` implementation.
|
||||||
|
|
||||||
|
|
||||||
## [0.2.3] - 2019-02-21
|
## [0.2.3] - 2019-02-21
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-utils"
|
name = "actix-utils"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix utils - various actix net related services"
|
description = "Actix utils - various actix net related services"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
@ -18,12 +18,12 @@ name = "actix_utils"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-service = "0.2.1"
|
actix-service = "0.2.2"
|
||||||
actix-codec = "0.1.0"
|
actix-codec = "0.1.0"
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
futures = "0.1"
|
futures = "0.1.24"
|
||||||
tokio-timer = "0.2.8"
|
tokio-timer = "0.2.8"
|
||||||
tokio-current-thread = "0.1"
|
tokio-current-thread = "0.1.4"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@ -10,7 +10,27 @@ pub type BoxedService<Req, Res, Err> = Box<
|
|||||||
>,
|
>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
pub type BoxedNewService<Req, Res, Err, InitErr> = Box<
|
/// Create boxed new service
|
||||||
|
pub fn new_service<T>(
|
||||||
|
service: T,
|
||||||
|
) -> BoxedNewService<T::Request, T::Response, T::Error, T::InitError>
|
||||||
|
where
|
||||||
|
T: NewService + 'static,
|
||||||
|
T::Service: 'static,
|
||||||
|
{
|
||||||
|
BoxedNewService(Box::new(NewServiceWrapper(service)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create boxed service
|
||||||
|
pub fn service<T>(service: T) -> BoxedService<T::Request, T::Response, T::Error>
|
||||||
|
where
|
||||||
|
T: Service + 'static,
|
||||||
|
T::Future: 'static,
|
||||||
|
{
|
||||||
|
Box::new(ServiceWrapper(service))
|
||||||
|
}
|
||||||
|
|
||||||
|
type Inner<Req, Res, Err, InitErr> = Box<
|
||||||
NewService<
|
NewService<
|
||||||
Request = Req,
|
Request = Req,
|
||||||
Response = Res,
|
Response = Res,
|
||||||
@ -21,24 +41,25 @@ pub type BoxedNewService<Req, Res, Err, InitErr> = Box<
|
|||||||
>,
|
>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Create boxed new service
|
pub struct BoxedNewService<Req, Res, Err, InitErr>(Inner<Req, Res, Err, InitErr>);
|
||||||
pub fn new_service<T>(
|
|
||||||
service: T,
|
|
||||||
) -> BoxedNewService<T::Request, T::Response, T::Error, T::InitError>
|
|
||||||
where
|
|
||||||
T: NewService + 'static,
|
|
||||||
T::Service: 'static,
|
|
||||||
{
|
|
||||||
Box::new(NewServiceWrapper(service))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create boxed service
|
impl<Req, Res, Err, InitErr> NewService for BoxedNewService<Req, Res, Err, InitErr>
|
||||||
pub fn service<T>(service: T) -> BoxedService<T::Request, T::Response, T::Error>
|
|
||||||
where
|
where
|
||||||
T: Service + 'static,
|
Req: 'static,
|
||||||
T::Future: '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<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);
|
struct NewServiceWrapper<T: NewService>(T);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user