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:
@ -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,
|
||||
|
Reference in New Issue
Block a user