diff --git a/src/connector.rs b/src/connector.rs index 00a88c5f..e8fbcfd3 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -56,6 +56,22 @@ impl Connect { } } + /// split the string by ':' and convert the second part to u16 + pub fn parse>(host: T) -> Option { + 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::() { + 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.