The traits/structs/fns that parse strings into IPv4, v6 and socket addresses are all private.
It would be nice if these weren't so developers could leverage them.
For instance, I would like to create a parser that can parse both IpAddr
s and SocketAddr
s (without the :port or with the :port). All the pieces to do this are there in std::net::parsers
, but they are private.
I mean I can do something hacky like
pub fn parse_ip_and_port(addr: &str) -> Result<(IpAddr, u16), &str> {
let sock_addr: Result<SocketAddr, AddrParseError> = addr.parse();
let mut res = sock_addr.map_err(|err| "err.description()")
.map(|sock| (sock.ip(), sock.port()));
if res.is_err() {
let ip_addr: Result<IpAddr, AddrParseError> = addr.parse();
res = ip_addr.map_err(|err| "err.description()")
.map(|ip| (ip, 0));
}
res
}
or some such, but it would be more efficient if I could get at some of the parser impls...