@@ -412,21 +412,24 @@ impl IpAddr {
412
412
/// # Examples
413
413
///
414
414
/// ```
415
- /// #![feature(ip)]
416
415
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
417
416
///
417
+ /// let localhost_v4 = Ipv4Addr::new(127, 0, 0, 1);
418
+ ///
419
+ /// assert_eq!(IpAddr::V4(localhost_v4).to_canonical(), localhost_v4);
420
+ /// assert_eq!(IpAddr::V6(localhost_v4.to_ipv6_mapped()).to_canonical(), localhost_v4);
418
421
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).to_canonical().is_loopback(), true);
419
422
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).is_loopback(), false);
420
423
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).to_canonical().is_loopback(), true);
421
424
/// ```
422
425
#[ inline]
423
426
#[ must_use = "this returns the result of the operation, \
424
427
without modifying the original"]
425
- #[ rustc_const_unstable ( feature = "const_ip " , issue = "76205 " ) ]
426
- #[ unstable ( feature = "ip " , issue = "27709 " ) ]
428
+ #[ stable ( feature = "ip_to_canonical " , since = "CURRENT_RUSTC_VERSION " ) ]
429
+ #[ rustc_const_stable ( feature = "ip_to_canonical " , since = "CURRENT_RUSTC_VERSION " ) ]
427
430
pub const fn to_canonical ( & self ) -> IpAddr {
428
431
match self {
429
- & v4 @ IpAddr :: V4 ( _) => v4 ,
432
+ IpAddr :: V4 ( _) => * self ,
430
433
IpAddr :: V6 ( v6) => v6. to_canonical ( ) ,
431
434
}
432
435
}
@@ -1750,11 +1753,11 @@ impl Ipv6Addr {
1750
1753
/// Some(Ipv4Addr::new(192, 10, 2, 255)));
1751
1754
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4_mapped(), None);
1752
1755
/// ```
1753
- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
1754
- #[ stable( feature = "ipv6_to_ipv4_mapped" , since = "1.63.0" ) ]
1756
+ #[ inline]
1755
1757
#[ must_use = "this returns the result of the operation, \
1756
1758
without modifying the original"]
1757
- #[ inline]
1759
+ #[ stable( feature = "ipv6_to_ipv4_mapped" , since = "1.63.0" ) ]
1760
+ #[ rustc_const_stable( feature = "const_ipv6_to_ipv4_mapped" , since = "CURRENT_RUSTC_VERSION" ) ]
1758
1761
pub const fn to_ipv4_mapped ( & self ) -> Option < Ipv4Addr > {
1759
1762
match self . octets ( ) {
1760
1763
[ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0xff , 0xff , a, b, c, d] => {
@@ -1819,11 +1822,11 @@ impl Ipv6Addr {
1819
1822
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).is_loopback(), false);
1820
1823
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).to_canonical().is_loopback(), true);
1821
1824
/// ```
1822
- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
1823
- #[ unstable( feature = "ip" , issue = "27709" ) ]
1825
+ #[ inline]
1824
1826
#[ must_use = "this returns the result of the operation, \
1825
1827
without modifying the original"]
1826
- #[ inline]
1828
+ #[ stable( feature = "ip_to_canonical" , since = "CURRENT_RUSTC_VERSION" ) ]
1829
+ #[ rustc_const_stable( feature = "ip_to_canonical" , since = "CURRENT_RUSTC_VERSION" ) ]
1827
1830
pub const fn to_canonical ( & self ) -> IpAddr {
1828
1831
if let Some ( mapped) = self . to_ipv4_mapped ( ) {
1829
1832
return IpAddr :: V4 ( mapped) ;
0 commit comments