-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
(Firstly, I saw the discussion around its removal in #923, but that decision appears to have been made before SocketAddr
was decided to have an enum structure like that of IpAddr
. I'm thinking maybe it was an oversight that IpAddr
was left out after that decision. In case it wasn't an oversight, here's my argument in favor of re-introducing IpAddr
.)
I propose that the type IpAddr
, as an enum with V4(Ipv4Addr)
and V6(Ipv6Addr)
variants should be re-added to std::net
. In my experience, it is often necessary to express an IP address that is either IPv4 or IPv6 without the address being associated with a socket and, therefore, it not having an associated port value. For example, when a server retains the remote addresses of past clients. In such cases, it is not intuitive to store such an address as a SocketAddr
instance. Also, the re-addition would mirror the SocketAddr
enum, which itself has V4
and V6
variants containing structures to the specific types.
Additionally, I propose that the std::net::LookupHost
type should be reverted to yield IpAddr
types rather than SocketAddr
as this also permits dealing with hostnames in cases where they are not directly related to any socket operations. It should be noted that the ToSocketAddrs
trait is already widely used within std::net
to yield a series of SocketAddr
instances and keeping lookup_host
as-is would constitute a duplication of this functionality.
With these changes, I think it would also be helpful to add a convenience method for creating SocketAddr
instances; e.g. fn new(ip: &IpAddr, port: u16) -> SocketAddr
.