-
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 missing examples for Ipv6Addr #37859
Conversation
@bors r+ rollup |
Travis error is unrelated. |
/// use std::net::Ipv6Addr; | ||
/// | ||
/// assert_eq!(Ipv6Addr::new(65280, 0, 0, 0, 0, 0, 0, 0).octets(), | ||
/// [65280, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
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 should be [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
.
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.
Yep, good catch!
@bors r- |
ab27645
to
f6c6ad9
Compare
Updated. @bors: delegate=frewsxcv |
✌️ @frewsxcv can now approve this pull request |
@bors r+ rollup |
📌 Commit f6c6ad9 has been approved by |
/// ``` | ||
/// use std::net::Ipv6Addr; | ||
/// | ||
/// let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 49152, 767); |
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 is a bad example, should use hex instead, since that’s the representation used most commonly.
Compare:
# for `2002:c000:2ff::` aka `::ffff:192.0.2.255`
let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff);
Using an 6to4 address is not a good idea either.
/// ``` | ||
/// use std::net::Ipv6Addr; | ||
/// | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 49152, 767).is_unspecified(), false); |
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.
Similarly, use hex please.
/// fn main() { | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 49152, 767).is_global(), true); | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).is_global(), false); | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 457, 0, 0, 45000, 0, 1).is_global(), true); |
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.
Compare:
# for ::1c9:0:0:afc8:0:1
Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 1)
@bors: r- |
f6c6ad9
to
cddb062
Compare
Updated. |
/// fn main() { | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_global(), true); | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1).is_global(), false); | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 0x1C9, 0, 0, 0xafc8, 0, 0x1).is_global(), true); |
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.
C in 0x1c9
is uppercase, despite of everything else being lowercase.
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.
Nice catch!
/// | ||
/// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4(), None); | ||
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4(), | ||
/// Some(Ipv4Addr::new(127, 0, 0, 1))); |
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 example doesn’t look right. 127.0.0.1
is ::ffff:7f00:0001
. What you have there now is 192.10.2.255
.
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.
Arf, indeed. Bad conversion!
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.
Probably also a good idea to show that e.g. ::1
converts to a 0.0.0.1
rather than None
(i.e. it does both decimal and 4to6 conversions)
cddb062
to
6ae20df
Compare
Updated. |
r=me I also wrote a comment like this:
which got immediately hidden by a commit, but even without that the PR looks fine to me now. |
Then let's let @frewsxcv decide. :) |
I think it would be good to include @nagisa's example, but I don't feel strongly. r=me with these changes. |
6ae20df
to
1a91fc6
Compare
📌 Commit 57be2d9 has been approved by |
@bors: r- |
57be2d9
to
a5049f7
Compare
@bors: r+ rollup |
📌 Commit a5049f7 has been approved by |
@bors: r=nagisa |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit a5049f7 has been approved by |
Add missing examples for Ipv6Addr r? @steveklabnik cc @frewsxcv
Add missing examples for Ipv6Addr r? @steveklabnik cc @frewsxcv
r? @steveklabnik
cc @frewsxcv