Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upIpv4Addr and Ipv6Addr convenience constructors. #44395
Conversation
rust-highfive
assigned
BurntSushi
Sep 7, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @BurntSushi (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
estebank
requested changes
Sep 7, 2017
| assert_eq!(Ipv6Addr::unspecified(), Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)); | ||
| assert!(Ipv6Addr::unspecified().is_unspecified()); | ||
| } | ||
|
|
This comment has been minimized.
This comment has been minimized.
| /// use std::net::Ipv4Addr; | ||
| /// | ||
| /// let addr = Ipv4Addr::localhost(); | ||
| /// assert_eq!(addr, Ipv4Addr::new(127, 0, 0, 1)); |
This comment has been minimized.
This comment has been minimized.
| /// use std::net::Ipv4Addr; | ||
| /// | ||
| /// let addr = Ipv4Addr::unspecified(); | ||
| /// assert_eq!(addr, Ipv4Addr::new(0, 0, 0, 0)); |
This comment has been minimized.
This comment has been minimized.
| /// use std::net::Ipv6Addr; | ||
| /// | ||
| /// let addr = Ipv6Addr::localhost(); | ||
| /// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); |
This comment has been minimized.
This comment has been minimized.
| /// use std::net::Ipv6Addr; | ||
| /// | ||
| /// let addr = Ipv6Addr::unspecified(); | ||
| /// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
alexcrichton
added
the
S-waiting-on-review
label
Sep 7, 2017
estebank
reviewed
Sep 8, 2017
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` |
This comment has been minimized.
This comment has been minimized.
estebank
Sep 8, 2017
Contributor
I believe you need to add # #![feature(ip)] to this and the other new examples in order for the doc tests to work. The first # hides the line from the docs (which you might not want to do to make it clear that it is needed for this usage).
jcdyer
force-pushed the
jcdyer:ip-constructors
branch
from
3572665
to
8b6122f
Sep 9, 2017
BurntSushi
requested changes
Sep 11, 2017
|
This looks reasonable to me, but I think these need stability attributes, and should be unstable for now. |
BurntSushi
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
Sep 11, 2017
This comment has been minimized.
This comment has been minimized.
|
Looks reasonable to me as well! @jcdyer mind adding the stability attributes and filing an issue to track the stability here? |
This comment has been minimized.
This comment has been minimized.
|
@estebank @BurntSushi I added the unstable attributes, and created a tracking issue. I'm not entirely sure what needs to happen, but I did my best based on a quick search of other similar examples. Let me know if anything needs to be different. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: rollup |
jcdyer commentedSep 7, 2017
•
edited
Introduce convenience constructors for common types.
This introduces the following constructors:
The recently added
Fromimplementations were nice for avoiding the fallibility of conversions from strings like"127.0.0.1".parse().unwrap(), and"::1".parse().unwrap(), but while the Ipv4 version is roughly comparable in verbosity, the Ipv6 version lacks zero-segment elision, which makes it significantly more awkward:[0, 0, 0, 0, 0, 0, 0, 0].into(). While there isn't a clear way to introduce zero elision to type that can infallibly be converted into Ipv6 addresses, this PR resolves the problem for the two most commonly used addresses, which, incidentally, are the ones that suffer the most from the lack of zero-segment elision.This change is dead simple, and introduces no backwards incompatibility.
See also, this topic on the inernals board