Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience methods to IpAddr #1554

Closed
canndrew opened this issue Mar 23, 2016 · 4 comments
Closed

Add convenience methods to IpAddr #1554

canndrew opened this issue Mar 23, 2016 · 4 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@canndrew
Copy link
Contributor

IpAddr should have at least the following methods:

/// Returns `true` if `self` is one of the two unspecified addresses
fn is_unspecified(&self) -> bool;

/// Returns `true` if `self` is a loopback address such as `127.0.0.1` or `::1`
fn is_loopback(&self) -> bool;

Edit: is_multicast and to_ipv6_{compatible,mapped} would make sense aswell although I have no need for them.

@canndrew
Copy link
Contributor Author

Another thing I'd like is the ability to quickly create localhost and/or unspecified addresses. I sometimes find myself writing SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port)) which is a very long way to say "localhost:port". A shorter version (when you can use ToSocketAddrs) is to write ("127.0.0.1", port) but then you're unnecessarily parsing a string every time the code runs.

Could we also add the following methods to the standard library?

fn Ipv4Addr::localhost() -> Ipv4Addr;
fn Ipv6Addr::localhost() -> Ipv6Addr;
fn IpAddr::localhost_v4() -> IpAddr;
fn IpAddr::localhost_v6() -> IpAddr;
fn SocketAddrV4::localhost(port: u16) -> SocketAddrV4;
fn SocketAddrV6::localhost(port: u16) - >SocketAddrV6;
fn SocketAddr::localhost_v4(port: u16) -> SocketAddr;
fn SocketAddr::localhost_v6(port: u16) -> SocketAddr;

And similarly for unspecified addresses?

@Anachron
Copy link

Anachron commented Apr 5, 2016

I suggest to start here: https://github.com/rust-lang/rfcs#before-creating-an-rfc
And follow the whole process. This RFC does not meet any standards or form :/

@canndrew
Copy link
Contributor Author

canndrew commented Apr 6, 2016

Well it's not really an RFC, just a couple of ideas. I could move them into an RFC if people think it's worth it.

@canndrew
Copy link
Contributor Author

canndrew commented Jul 7, 2016

This is fixed in rust-lang/rust#34694

@canndrew canndrew closed this as completed Jul 7, 2016
@Centril Centril added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

3 participants