/// Convert Server string to Server Address
Convert Server string to Server Address
Convert Server string to Server Address
fn server_str_to_server_addr(
    server_str: &Option<String>,
) -> Result<Option<ServerAddress>, IoError> {
    if let Some(server) = server_str {
        // parse host and port
        let host_port: Vec<&str> = server.split(':').collect();
        if host_port.len() != 2 {
            return Err(IoError::new(
                ErrorKind::InvalidData,
                format!("Expected 'host:port' format, found '{}'", server),
            ));
        }
        let host = host_port[0].to_owned();
        let port: u16 = host_port[1].parse().map_err(|err| {
            IoError::new(ErrorKind::InvalidInput, format!("invalid port: {}", err))
        })?;
        Ok(Some(ServerAddress { host, port }))
    } else {
        Ok(None)
    }
}
fn server_str_to_server_addr ( server_str : & Option < String > , ) -> Result < Option < ServerAddress > , IoError > { if let Some ( server ) = server_str { // parse host and port let host_port : Vec < & str > = server . split ( ':' ) . collect ( ) ; if host_port . len ( ) != 2 { return Err ( IoError :: new ( ErrorKind :: InvalidData , format ! ( " " server ) , ) ) ; } let host = host_port [ 0 ] . to_owned ( ) ; let port : u16 = host_port [ 1 ] . parse ( ) . map_err ( | err | { IoError :: new ( ErrorKind :: InvalidInput , format ! ( " " err ) ) } ) ? ; Ok ( Some ( ServerAddress { host , port } ) ) } else { Ok ( None ) } }
Convert Server string to Server Address
Convert Server string to Server Address
server_str
&Option<String>