1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 19:12:56 +01:00

add Connect::parse() method

This commit is contained in:
Nikolay Kim 2018-10-29 13:41:54 -07:00
parent c15e4b92a8
commit 4b16af29c7

View File

@ -56,6 +56,22 @@ impl Connect {
}
}
/// split the string by ':' and convert the second part to u16
pub fn parse<T: AsRef<str>>(host: T) -> Option<Connect> {
let mut parts_iter = host.as_ref().splitn(2, ':');
if let Some(host) = parts_iter.next() {
let port_str = parts_iter.next().unwrap_or("");
if let Ok(port) = port_str.parse::<u16>() {
return Some(Connect {
port,
host: host.to_owned(),
timeout: Duration::from_secs(1),
});
}
}
None
}
/// Set connect timeout
///
/// By default timeout is set to a 1 second.