mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-18 06:11:50 +01:00
Custom BoxedNewService implementation
This commit is contained in:
parent
a97d7f0ccf
commit
6ea128fac5
@ -1,5 +1,12 @@
|
||||
# Changes
|
||||
|
||||
## [0.2.4] - 2019-02-21
|
||||
|
||||
### Changed
|
||||
|
||||
* Custom `BoxedNewService` implementation.
|
||||
|
||||
|
||||
## [0.2.3] - 2019-02-21
|
||||
|
||||
### Added
|
||||
|
@ -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"]
|
||||
@ -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]
|
||||
|
@ -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<
|
||||
Request = Req,
|
||||
Response = Res,
|
||||
@ -21,24 +41,25 @@ 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,
|
||||
{
|
||||
Box::new(NewServiceWrapper(service))
|
||||
}
|
||||
pub struct BoxedNewService<Req, Res, Err, InitErr>(Inner<Req, Res, Err, InitErr>);
|
||||
|
||||
/// Create boxed service
|
||||
pub fn service<T>(service: T) -> BoxedService<T::Request, T::Response, T::Error>
|
||||
impl<Req, Res, Err, InitErr> NewService for BoxedNewService<Req, Res, Err, InitErr>
|
||||
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<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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user