mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 21:22:57 +01:00
add Connect::parse() method
This commit is contained in:
parent
c15e4b92a8
commit
4b16af29c7
@ -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
|
/// Set connect timeout
|
||||||
///
|
///
|
||||||
/// By default timeout is set to a 1 second.
|
/// By default timeout is set to a 1 second.
|
||||||
|
Loading…
Reference in New Issue
Block a user