nix icon indicating copy to clipboard operation
nix copied to clipboard

impl std::net::ToSocketAddrs for SockaddrIn / SockaddrIn6 / SockaddrStorage

Open isomer opened this issue 3 years ago • 0 comments
trafficstars

Many high level libraries will accept anything that implements std::net::ToSocketAddrs as an address (eg: std::net::TcpListener::bind(), tokio::net::UdpSocket::bind() etc), but the various nix Sockaddr* types don't implement this.

nix already implements From<SockaddrIn> for std::net::SocketAddrV4 / From<SockaddrIn6> for std::net::SocketAddrV6. These can then be converted into a std::net::SocketAddr and returned in a std::iter::once().

For SockaddrStorage, similar can apply, but std::iter::empty() can be returned if the type isn't convertable to a std::net::SocketAddr.

This would give a lot of friendliness for getting an address from one of the low level API then using it in a high level API.

isomer avatar Aug 18 '22 21:08 isomer