use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; type SocketVec = Vec; pub trait ToIPv4Vec { fn to_ipv4_vec(self) -> Vec; } pub trait ToIPv6Vec { fn to_ipv6_vec(self) -> Vec; } pub trait ToPTRVec { fn to_ptr_vec(self) -> Vec; } impl ToIPv4Vec for SocketVec { fn to_ipv4_vec(self) -> Vec { self.into_iter() .filter_map(|ip| match ip.ip() { IpAddr::V4(ip) => Some(ip), IpAddr::V6(_) => None, }) .collect::>() } } impl ToIPv6Vec for SocketVec { fn to_ipv6_vec(self) -> Vec { self.into_iter() .filter_map(|ip| match ip.ip() { IpAddr::V4(_) => None, IpAddr::V6(ip) => Some(ip), }) .collect::>() } } impl ToPTRVec for SocketVec { fn to_ptr_vec(self) -> Vec { self.into_iter() .map(|ip| ip.ip().to_string()) .collect::>() } }