1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-27 01:37:42 +02:00

make service Request type generic

This commit is contained in:
Nikolay Kim
2019-03-05 07:35:26 -08:00
parent e8a49801eb
commit dfbb77f98d
34 changed files with 622 additions and 747 deletions

View File

@ -1,5 +1,10 @@
# Changes
## [0.4.0] - 2019-03-xx
* Upgrade actix-service
## [0.3.1] - 2019-03-04
### Added

View File

@ -169,8 +169,8 @@ impl ServiceRuntime {
pub fn service<T, F>(&mut self, name: &str, service: F)
where
F: IntoNewService<T>,
T: NewService<Request = TcpStream, Response = ()> + 'static,
F: IntoNewService<T, TcpStream>,
T: NewService<TcpStream, Response = ()> + 'static,
T::Future: 'static,
T::Service: 'static,
T::InitError: fmt::Debug,
@ -191,7 +191,7 @@ impl ServiceRuntime {
type BoxedNewService = Box<
NewService<
Request = (Option<CounterGuard>, ServerMessage),
(Option<CounterGuard>, ServerMessage),
Response = (),
Error = (),
InitError = (),
@ -204,15 +204,14 @@ struct ServiceFactory<T> {
inner: T,
}
impl<T> NewService for ServiceFactory<T>
impl<T> NewService<(Option<CounterGuard>, ServerMessage)> for ServiceFactory<T>
where
T: NewService<Request = TcpStream, Response = ()>,
T: NewService<TcpStream, Response = ()>,
T::Future: 'static,
T::Service: 'static,
T::Error: 'static,
T::InitError: fmt::Debug + 'static,
{
type Request = (Option<CounterGuard>, ServerMessage);
type Response = ();
type Error = ();
type InitError = ();
@ -220,14 +219,9 @@ where
type Future = Box<Future<Item = BoxedServerService, Error = ()>>;
fn new_service(&self, _: &()) -> Self::Future {
Box::new(
self.inner
.new_service(&())
.map_err(|_| ())
.map(|s| {
let service: BoxedServerService = Box::new(StreamService::new(s));
service
}),
)
Box::new(self.inner.new_service(&()).map_err(|_| ()).map(|s| {
let service: BoxedServerService = Box::new(StreamService::new(s));
service
}))
}
}

View File

@ -23,7 +23,7 @@ pub(crate) enum ServerMessage {
}
pub trait ServiceFactory: Send + Clone + 'static {
type NewService: NewService<Request = TcpStream>;
type NewService: NewService<TcpStream>;
fn create(&self) -> Self::NewService;
}
@ -38,7 +38,7 @@ pub(crate) trait InternalServiceFactory: Send {
pub(crate) type BoxedServerService = Box<
Service<
Request = (Option<CounterGuard>, ServerMessage),
(Option<CounterGuard>, ServerMessage),
Response = (),
Error = (),
Future = FutureResult<(), ()>,
@ -55,13 +55,12 @@ impl<T> StreamService<T> {
}
}
impl<T> Service for StreamService<T>
impl<T> Service<(Option<CounterGuard>, ServerMessage)> for StreamService<T>
where
T: Service<Request = TcpStream>,
T: Service<TcpStream>,
T::Future: 'static,
T::Error: 'static,
{
type Request = (Option<CounterGuard>, ServerMessage);
type Response = ();
type Error = ();
type Future = FutureResult<(), ()>;
@ -155,7 +154,7 @@ impl InternalServiceFactory for Box<InternalServiceFactory> {
impl<F, T> ServiceFactory for F
where
F: Fn() -> T + Send + Clone + 'static,
T: NewService<Request = TcpStream>,
T: NewService<TcpStream>,
{
type NewService = T;