@@ -822,10 +822,10 @@ impl Ipv4Addr {
822
822
/// ```
823
823
/// use std::net::{Ipv4Addr, Ipv6Addr};
824
824
///
825
- /// assert_eq!(
826
- /// Ipv4Addr ::new(192 , 0, 2, 255).to_ipv6_compatible(),
827
- /// Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc000, 0x2ff)
828
- /// );
825
+ /// // ::192.0.2.255
826
+ /// let ipv6_compatible = Ipv6Addr ::new(0 , 0, 0, 0, 0, 0, 0xc000, 0x2ff);
827
+ ///
828
+ /// assert_eq!(Ipv4Addr::new(192, 0, 2, 255).to_ipv6_compatible(), ipv6_compatible );
829
829
/// ```
830
830
#[ rustc_const_stable( feature = "const_ipv4" , since = "1.50.0" ) ]
831
831
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -849,8 +849,10 @@ impl Ipv4Addr {
849
849
/// ```
850
850
/// use std::net::{Ipv4Addr, Ipv6Addr};
851
851
///
852
- /// assert_eq!(Ipv4Addr::new(192, 0, 2, 255).to_ipv6_mapped(),
853
- /// Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x2ff));
852
+ /// // ::ffff:192.0.2.255
853
+ /// let ipv6_mapped = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x2ff);
854
+ ///
855
+ /// assert_eq!(Ipv4Addr::new(192, 0, 2, 255).to_ipv6_mapped(), ipv6_mapped);
854
856
/// ```
855
857
#[ rustc_const_stable( feature = "const_ipv4" , since = "1.50.0" ) ]
856
858
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1599,10 +1601,18 @@ impl Ipv6Addr {
1599
1601
///
1600
1602
/// use std::net::{Ipv4Addr, Ipv6Addr};
1601
1603
///
1604
+ /// let ipv4 = Ipv4Addr::new(192, 10, 2, 255);
1605
+ /// let ipv6_compatible = ipv4.to_ipv6_compatible();
1606
+ /// let ipv6_mapped = ipv4.to_ipv6_mapped();
1607
+ ///
1608
+ /// // Only IPv4-mapped addresses are converted.
1609
+ /// assert_eq!(ipv6_compatible.to_ipv4_mapped(), None);
1610
+ /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc00a, 0x2ff).to_ipv4_mapped(), None);
1611
+ /// assert_eq!(ipv6_mapped.to_ipv4_mapped(), Some(ipv4));
1612
+ /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4_mapped(), Some(ipv4));
1613
+ ///
1614
+ /// // Addresses that are neither an IPv4-compatible or IPv4-mapped address are not converted.
1602
1615
/// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4_mapped(), None);
1603
- /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4_mapped(),
1604
- /// Some(Ipv4Addr::new(192, 10, 2, 255)));
1605
- /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4_mapped(), None);
1606
1616
/// ```
1607
1617
#[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
1608
1618
#[ unstable( feature = "ip" , issue = "27709" ) ]
@@ -1632,11 +1642,18 @@ impl Ipv6Addr {
1632
1642
/// ```
1633
1643
/// use std::net::{Ipv4Addr, Ipv6Addr};
1634
1644
///
1645
+ /// let ipv4 = Ipv4Addr::new(192, 10, 2, 255);
1646
+ /// let ipv6_compatible = ipv4.to_ipv6_compatible();
1647
+ /// let ipv6_mapped = ipv4.to_ipv6_mapped();
1648
+ ///
1649
+ /// // Both IPv4-compatible and IPv4-mapped addresses are converted.
1650
+ /// assert_eq!(ipv6_compatible.to_ipv4(), Some(ipv4));
1651
+ /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc00a, 0x2ff).to_ipv4(), Some(ipv4));
1652
+ /// assert_eq!(ipv6_mapped.to_ipv4(), Some(ipv4));
1653
+ /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4(), Some(ipv4));
1654
+ ///
1655
+ /// // Addresses that are neither an IPv4-compatible or IPv4-mapped address are not converted.
1635
1656
/// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4(), None);
1636
- /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4(),
1637
- /// Some(Ipv4Addr::new(192, 10, 2, 255)));
1638
- /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4(),
1639
- /// Some(Ipv4Addr::new(0, 0, 0, 1)));
1640
1657
/// ```
1641
1658
#[ rustc_const_stable( feature = "const_ipv6" , since = "1.50.0" ) ]
1642
1659
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments