pub fn is_valid_ipv4_port(input: &String) -> bool {
let parts: Vec<&str> = input.split(':').collect();
if parts.len() != 2 {
return false;
}
let ip_addr = parts[0];
if !is_valid_ipv4(ip_addr) {
return false;
}
let port = parts[1];
match port.parse::<u16>() {
Ok(_) => true,
Err(_) => false,
}
}
fn is_valid_ipv4(ip: &str) -> bool {
if let Ok(addr) = ip.parse::<std::net::Ipv4Addr>() {
addr.to_string() == ip
} else {
false
}
}
pub fn search_vec<T: PartialEq>(arr : &Vec<T> , key : &T) -> i32{
for index in 0..arr.len(){
if arr[index] == *key{
return index.try_into().unwrap();
}
}
return -1;
}