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

Ipv4Addr and Ipv6Addr convenience constructors. #44395

Merged
merged 4 commits into from Sep 17, 2017

Conversation

Projects
None yet
6 participants
@jcdyer
Copy link
Contributor

jcdyer commented Sep 7, 2017

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

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

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_eq!(Ipv6Addr::unspecified(), Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0));
assert!(Ipv6Addr::unspecified().is_unspecified());
}

This comment has been minimized.

@estebank

estebank Sep 7, 2017

Contributor

Trim the trailing whitespace.

/// use std::net::Ipv4Addr;
///
/// let addr = Ipv4Addr::localhost();
/// assert_eq!(addr, Ipv4Addr::new(127, 0, 0, 1));

This comment has been minimized.

@estebank

estebank Sep 7, 2017

Contributor

missing line closing the code example:

/// ```
/// use std::net::Ipv4Addr;
///
/// let addr = Ipv4Addr::unspecified();
/// assert_eq!(addr, Ipv4Addr::new(0, 0, 0, 0));

This comment has been minimized.

@estebank

estebank Sep 7, 2017

Contributor

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));

This comment has been minimized.

@estebank

estebank Sep 7, 2017

Contributor

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));

This comment has been minimized.

@estebank

estebank Sep 7, 2017

Contributor

missing line closing the code example:

/// ```

This comment has been minimized.

@jcdyer

jcdyer Sep 8, 2017

Author Contributor

All resolved. Thanks.

///
/// # Examples
///
/// ```

This comment has been minimized.

@estebank

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 jcdyer force-pushed the jcdyer:ip-constructors branch from 3572665 to 8b6122f Sep 9, 2017

@BurntSushi
Copy link
Member

BurntSushi left a comment

This looks reasonable to me, but I think these need stability attributes, and should be unstable for now.

cc @rust-lang/libs

@alexcrichton

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Member

alexcrichton commented Sep 15, 2017

Looks great, thanks @jcdyer!

@bors: r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Sep 15, 2017

📌 Commit 9d5b0e1 has been approved by alexcrichton

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Sep 16, 2017

@bors: rollup

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 16, 2017

Rollup merge of rust-lang#44395 - jcdyer:ip-constructors, r=alexcrichton
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)

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Sep 16, 2017

Rollup merge of rust-lang#44395 - jcdyer:ip-constructors, r=alexcrichton
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)

bors added a commit that referenced this pull request Sep 16, 2017

bors added a commit that referenced this pull request Sep 16, 2017

bors added a commit that referenced this pull request Sep 16, 2017

bors added a commit that referenced this pull request Sep 16, 2017

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 16, 2017

Rollup merge of rust-lang#44395 - jcdyer:ip-constructors, r=alexcrichton
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)

bors added a commit that referenced this pull request Sep 16, 2017

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 16, 2017

Rollup merge of rust-lang#44395 - jcdyer:ip-constructors, r=alexcrichton
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)

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 17, 2017

Rollup merge of rust-lang#44395 - jcdyer:ip-constructors, r=alexcrichton
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)

bors added a commit that referenced this pull request Sep 17, 2017

@bors bors merged commit 9d5b0e1 into rust-lang:master Sep 17, 2017

1 check failed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.