1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-29 16:14:58 +02:00

add Either service

This commit is contained in:
Nikolay Kim
2018-09-27 17:05:48 -07:00
parent ba57e67a74
commit d19ed8b00a
3 changed files with 119 additions and 0 deletions

View File

@ -12,8 +12,11 @@ use service::{NewService, Service};
/// Server message
pub enum ServerMessage {
/// New stream
Connect(net::TcpStream),
/// Gracefull shutdown
Shutdown(Duration),
/// Force shutdown
ForceShutdown,
}
@ -220,6 +223,18 @@ impl InternalServiceFactory for Box<InternalServiceFactory> {
}
}
impl<F, T> ServiceFactory for F
where
F: Fn() -> T + Send + Clone + 'static,
T: NewService<Request = ServerMessage, Response = (), Error = (), InitError = ()>,
{
type NewService = T;
fn create(&self) -> T {
(self)()
}
}
impl<F, T> StreamServiceFactory for F
where
F: Fn() -> T + Send + Clone + 'static,