1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 18:37:41 +02:00

Impl From<usize> and From<Option<usize>> for KeepAlive

This commit is contained in:
messense
2018-03-10 17:40:36 +08:00
parent 3dd8fdf450
commit 9a404a0c03
3 changed files with 30 additions and 4 deletions

View File

@ -44,6 +44,22 @@ pub enum KeepAlive {
Disabled,
}
impl From<usize> for KeepAlive {
fn from(keepalive: usize) -> Self {
KeepAlive::Timeout(keepalive)
}
}
impl From<Option<usize>> for KeepAlive {
fn from(keepalive: Option<usize>) -> Self {
if let Some(keepalive) = keepalive {
KeepAlive::Timeout(keepalive)
} else {
KeepAlive::Disabled
}
}
}
/// Pause accepting incoming connections
///
/// If socket contains some pending connection, they might be dropped.

View File

@ -124,8 +124,8 @@ impl<H> HttpServer<H> where H: IntoHttpHandler + 'static
/// Set server keep-alive setting.
///
/// By default keep alive is set to a `Os`.
pub fn keep_alive(mut self, val: KeepAlive) -> Self {
self.keep_alive = val;
pub fn keep_alive<T: Into<KeepAlive>>(mut self, val: T) -> Self {
self.keep_alive = val.into();
self
}