-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 Ipv6Addr::to_ipv4_mapped #75019
Add Ipv6Addr::to_ipv4_mapped #75019
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @hanna-kruppe (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. |
a89e2ed
to
5f0be61
Compare
/// Some(Ipv4Addr::new(192, 10, 2, 255))); | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4_mapped(), None); | ||
/// ``` | ||
pub fn to_ipv4_mapped(&self) -> Option<Ipv4Addr> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn to_ipv4_mapped(&self) -> Option<Ipv4Addr> { | |
#[unstable(feature = "ipv4_mapped", issue = "none")] | |
pub fn to_ipv4_mapped(&self) -> Option<Ipv4Addr> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need to add #![feature(ipv4_mapped)]
to the lib.rs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, certainly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although there is already an unstable feature named ip
, do I still need to add a new unstable feature?
#27709
https://github.com/rust-lang/rust/blob/master/library/std/src/net/ip.rs#L1-L7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked on Zulip and it looks like adding stuff to existing unstable features is fine. So just use the ip
feature :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you requested another review: the unstable
attribute is still missing. Please add #[unstable(feature = "ip", issue = "27709")]
right above the line containing pub fn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the following lines have been added at the beginning of this file (ip.rs
):
#![unstable(
feature = "ip",
reason = "extra functionality has not been \
scrutinized to the level that it should \
be to be stable",
issue = "27709"
)]
Adding #[unstable(feature = "ip", issue = "27709")]
above this fn is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(It is better to give a permanent link to those code lines in the future).
c889fc3
to
288784e
Compare
@lzutao is right, the deprecation should not happen before the replacement is stable. It's also not clear to me why the deprecation in the IETF RFC ("New or updated implementations are not required to support this address type.") should translate to a deprecation of the Rust API (which remains useful for any particular implementation that intends to support such addresses in some way). Both issues can be side-stepped by only adding the new encoding for now, without deprecating anything. Deprecating could be a separate discussion at a later date (e.g., after stabilization of the new API) and should probably go through @rust-lang/libs in some way. |
There is no replacement for
|
Do you want to fix it in a different PR although the intention is to deprecate it ? |
@lzutao If we want to fix it, we may need to change the return type of |
Perhaps it should be discussed when to deprecate |
Deprecating a stable method without deprecation sounds like something that needs a @rust-lang/libs FCP, so (rolls dice) r? @LukasKalbertodt |
288784e
to
4639fe8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know a lot about IP6 and that stuff, but since it looks like the RFC defines these mappable addresses, it seems useful to add this method, I think.
@hanna-kruppe @lzutao Do you agree adding this as unstable makes sense?
/// Some(Ipv4Addr::new(192, 10, 2, 255))); | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4_mapped(), None); | ||
/// ``` | ||
pub fn to_ipv4_mapped(&self) -> Option<Ipv4Addr> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still need to add the unstable attribute.
I don't know much about networking either, but FWIW I do agree. |
4639fe8
to
306860a
Compare
306860a
to
124d777
Compare
library/std/src/net/ip.rs
Outdated
/// Converts this address to an [IPv4 address] if it's an "IPv4-mapped IPv6 address" | ||
/// defined in [IETF RFC 4291 section 2.5.5.2], otherwise returns [`None`]. | ||
/// | ||
/// ::ffff:a.b.c.d becomes a.b.c.d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This paragraph should still be improved. See my suggestion here
/// Some(Ipv4Addr::new(192, 10, 2, 255))); | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4_mapped(), None); | ||
/// ``` | ||
pub fn to_ipv4_mapped(&self) -> Option<Ipv4Addr> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you requested another review: the unstable
attribute is still missing. Please add #[unstable(feature = "ip", issue = "27709")]
right above the line containing pub fn
.
124d777
to
d892a07
Compare
Thanks, the docs look fine now. But I am somewhat confused: the |
@LukasKalbertodt |
📌 Commit d892a07 has been approved by |
🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened |
☀️ Test successful - checks-actions, checks-azure |
…le, r=LukasKalbertodt Add a note for Ipv4Addr::to_ipv6_compatible Previous discussion: rust-lang#75019 > I think adding a comment saying "This isn't typically the method you want; these addresses don't typically function on modern systems. Use `to_ipv6_mapped` instead." would be a good first step, whether this method gets marked as deprecated or not. _Originally posted by @joshtriplett in rust-lang#75150 (comment)
Move stability attribute for items under the `ip` feature The `#[unstable]` attribute for items under the `ip` feature is currently located on the `std::net::ip` module itself. This is unusual, and less readable. This has sidetracked discussion about these items numerous times (rust-lang#60145 (comment), rust-lang#76098 (comment), rust-lang#76098 (comment), rust-lang#75019 (comment), rust-lang#75019 (comment)) and lead to incorrect assumptions about which items are actually stable (rust-lang#60145 (comment), rust-lang#76098 (comment)). This PR moves the attribute from the module to the items themselves.
Move stability attribute for items under the `ip` feature The `#[unstable]` attribute for items under the `ip` feature is currently located on the `std::net::ip` module itself. This is unusual, and less readable. This has sidetracked discussion about these items numerous times (rust-lang#60145 (comment), rust-lang#76098 (comment), rust-lang#76098 (comment), rust-lang#75019 (comment), rust-lang#75019 (comment)) and lead to incorrect assumptions about which items are actually stable (rust-lang#60145 (comment), rust-lang#76098 (comment)). This PR moves the attribute from the module to the items themselves.
deprecate Ipv4Addr::to_ipv6_compatible & Ipv6Addr::to_ipv4reference: Add a note for Ipv4Addr::to_ipv6_compatible #75150According to IETF RFC 4291, the "IPv4-Compatible IPv6 address" is deprecated.
And the current implementation of
Ipv4Addr::to_ipv6_compatible
is incorrect: it does not check whether the IPv4 address is a globally-unique IPv4 unicast address.Please let me know if there are any issues with this pull request.