We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1a91fc6 commit b6bfdb8Copy full SHA for b6bfdb8
src/libstd/net/ip.rs
@@ -792,10 +792,14 @@ impl Ipv6Addr {
792
/// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4(), None);
793
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4(),
794
/// Some(Ipv4Addr::new(192, 10, 2, 255)));
795
+ /// // ::1 is localhost in IPv6, equivalent to 127.0.0.0/8 in IPv4:
796
+ /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4(),
797
+ /// Some(Ipv4Addr::new(127, 0, 0, 1)));
798
/// ```
799
#[stable(feature = "rust1", since = "1.0.0")]
800
pub fn to_ipv4(&self) -> Option<Ipv4Addr> {
801
match self.segments() {
802
+ [0, 0, 0, 0, 0, 0, 0, 1] => Some(Ipv4Addr::new(127, 0, 0, 1)),
803
[0, 0, 0, 0, 0, f, g, h] if f == 0 || f == 0xffff => {
804
Some(Ipv4Addr::new((g >> 8) as u8, g as u8,
805
(h >> 8) as u8, h as u8))
0 commit comments