Uh oh!
There was an error while loading. Please reload this page.
Ipv4Addr and Ipv6Addr convenience constructors. - #44395
Conversation
rust-highfive
commented
Sep 7, 2017
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. |
| assert!(Ipv6Addr::localhost().is_loopback()); | ||
| assert_eq!(Ipv6Addr::unspecified(), Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)); | ||
| assert!(Ipv6Addr::unspecified().is_unspecified()); | ||
| } |
| /// use std::net::Ipv4Addr; | ||
| /// | ||
| /// let addr = Ipv4Addr::localhost(); | ||
| /// assert_eq!(addr, Ipv4Addr::new(127, 0, 0, 1)); |
There was a problem hiding this comment.
missing line closing the code example:
/// ```
| /// use std::net::Ipv4Addr; | ||
| /// | ||
| /// let addr = Ipv4Addr::unspecified(); | ||
| /// assert_eq!(addr, Ipv4Addr::new(0, 0, 0, 0)); |
There was a problem hiding this comment.
missing line closing the code example:
/// ```
| /// use std::net::Ipv6Addr; | ||
| /// | ||
| /// let addr = Ipv6Addr::localhost(); | ||
| /// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); |
There was a problem hiding this comment.
missing line closing the code example:
/// ```
| /// use std::net::Ipv6Addr; | ||
| /// | ||
| /// let addr = Ipv6Addr::unspecified(); | ||
| /// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)); |
There was a problem hiding this comment.
missing line closing the code example:
/// ```
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` |
There was a problem hiding this comment.
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).
BurntSushi
left a comment
There was a problem hiding this comment.
This looks reasonable to me, but I think these need stability attributes, and should be unstable for now.
cc @rust-lang/libs
alexcrichton
commented
Sep 14, 2017
Looks reasonable to me as well! @jcdyer mind adding the stability attributes and filing an issue to track the stability here? |
jcdyer
commented
Sep 15, 2017
@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. |
alexcrichton
commented
Sep 15, 2017
bors
commented
Sep 15, 2017
📌 Commit 9d5b0e1 has been approved by |
alexcrichton
commented
Sep 16, 2017
@bors: rollup |
Ipv4Addr and Ipv6Addr convenience constructors. Introduce convenience constructors for common types. This introduces the following constructors: * Ipv6Addr::localhost() * Ipv6Addr::unspecified() * Ipv4Addr::localhost() * Ipv4Addr::unspecified() The recently added `From` implementations 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](https://internals.rust-lang.org/t/pre-rfc-convenience-ip-address-constructors/5878)
Ipv4Addr and Ipv6Addr convenience constructors. Introduce convenience constructors for common types. This introduces the following constructors: * Ipv6Addr::localhost() * Ipv6Addr::unspecified() * Ipv4Addr::localhost() * Ipv4Addr::unspecified() The recently added `From` implementations 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](https://internals.rust-lang.org/t/pre-rfc-convenience-ip-address-constructors/5878)
Ipv4Addr and Ipv6Addr convenience constructors. Introduce convenience constructors for common types. This introduces the following constructors: * Ipv6Addr::localhost() * Ipv6Addr::unspecified() * Ipv4Addr::localhost() * Ipv4Addr::unspecified() The recently added `From` implementations 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](https://internals.rust-lang.org/t/pre-rfc-convenience-ip-address-constructors/5878)
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