@@ -361,8 +361,9 @@ impl Ipv4Addr {
361
361
/// let addr = Ipv4Addr::new(127, 0, 0, 1);
362
362
/// assert_eq!(addr.octets(), [127, 0, 0, 1]);
363
363
/// ```
364
+ #[ rustc_const_stable( feature = "const_ipv4" , since = "1.48.0" ) ]
364
365
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
365
- pub fn octets ( & self ) -> [ u8 ; 4 ] {
366
+ pub const fn octets ( & self ) -> [ u8 ; 4 ] {
366
367
// This returns the order we want because s_addr is stored in big-endian.
367
368
self . inner . s_addr . to_ne_bytes ( )
368
369
}
@@ -404,8 +405,9 @@ impl Ipv4Addr {
404
405
/// assert_eq!(Ipv4Addr::new(127, 0, 0, 1).is_loopback(), true);
405
406
/// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_loopback(), false);
406
407
/// ```
408
+ #[ rustc_const_stable( feature = "const_ipv4" , since = "1.48.0" ) ]
407
409
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
408
- pub fn is_loopback ( & self ) -> bool {
410
+ pub const fn is_loopback ( & self ) -> bool {
409
411
self . octets ( ) [ 0 ] == 127
410
412
}
411
413
@@ -433,8 +435,9 @@ impl Ipv4Addr {
433
435
/// assert_eq!(Ipv4Addr::new(192, 168, 0, 2).is_private(), true);
434
436
/// assert_eq!(Ipv4Addr::new(192, 169, 0, 2).is_private(), false);
435
437
/// ```
438
+ #[ rustc_const_stable( feature = "const_ipv4" , since = "1.48.0" ) ]
436
439
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
437
- pub fn is_private ( & self ) -> bool {
440
+ pub const fn is_private ( & self ) -> bool {
438
441
match self . octets ( ) {
439
442
[ 10 , ..] => true ,
440
443
[ 172 , b, ..] if b >= 16 && b <= 31 => true ,
@@ -459,8 +462,9 @@ impl Ipv4Addr {
459
462
/// assert_eq!(Ipv4Addr::new(169, 254, 10, 65).is_link_local(), true);
460
463
/// assert_eq!(Ipv4Addr::new(16, 89, 10, 65).is_link_local(), false);
461
464
/// ```
465
+ #[ rustc_const_stable( feature = "const_ipv4" , since = "1.48.0" ) ]
462
466
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
463
- pub fn is_link_local ( & self ) -> bool {
467
+ pub const fn is_link_local ( & self ) -> bool {
464
468
match self . octets ( ) {
465
469
[ 169 , 254 , ..] => true ,
466
470
_ => false ,
@@ -573,7 +577,8 @@ impl Ipv4Addr {
573
577
/// assert_eq!(Ipv4Addr::new(100, 127, 255, 255).is_shared(), true);
574
578
/// assert_eq!(Ipv4Addr::new(100, 128, 0, 0).is_shared(), false);
575
579
/// ```
576
- pub fn is_shared ( & self ) -> bool {
580
+ #[ rustc_const_stable( feature = "const_ipv4" , since = "1.48.0" ) ]
581
+ pub const fn is_shared ( & self ) -> bool {
577
582
self . octets ( ) [ 0 ] == 100 && ( self . octets ( ) [ 1 ] & 0b1100_0000 == 0b0100_0000 )
578
583
}
579
584
@@ -605,7 +610,8 @@ impl Ipv4Addr {
605
610
/// assert_eq!(Ipv4Addr::new(192, 0, 1, 0).is_ietf_protocol_assignment(), false);
606
611
/// assert_eq!(Ipv4Addr::new(191, 255, 255, 255).is_ietf_protocol_assignment(), false);
607
612
/// ```
608
- pub fn is_ietf_protocol_assignment ( & self ) -> bool {
613
+ #[ rustc_const_stable( feature = "const_ipv4" , since = "1.48.0" ) ]
614
+ pub const fn is_ietf_protocol_assignment ( & self ) -> bool {
609
615
self . octets ( ) [ 0 ] == 192 && self . octets ( ) [ 1 ] == 0 && self . octets ( ) [ 2 ] == 0
610
616
}
611
617
@@ -628,7 +634,8 @@ impl Ipv4Addr {
628
634
/// assert_eq!(Ipv4Addr::new(198, 19, 255, 255).is_benchmarking(), true);
629
635
/// assert_eq!(Ipv4Addr::new(198, 20, 0, 0).is_benchmarking(), false);
630
636
/// ```
631
- pub fn is_benchmarking ( & self ) -> bool {
637
+ #[ rustc_const_stable( feature = "const_ipv4" , since = "1.48.0" ) ]
638
+ pub const fn is_benchmarking ( & self ) -> bool {
632
639
self . octets ( ) [ 0 ] == 198 && ( self . octets ( ) [ 1 ] & 0xfe ) == 18
633
640
}
634
641
@@ -681,8 +688,9 @@ impl Ipv4Addr {
681
688
/// assert_eq!(Ipv4Addr::new(236, 168, 10, 65).is_multicast(), true);
682
689
/// assert_eq!(Ipv4Addr::new(172, 16, 10, 65).is_multicast(), false);
683
690
/// ```
691
+ #[ rustc_const_stable( feature = "const_ipv4" , since = "1.48.0" ) ]
684
692
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
685
- pub fn is_multicast ( & self ) -> bool {
693
+ pub const fn is_multicast ( & self ) -> bool {
686
694
self . octets ( ) [ 0 ] >= 224 && self . octets ( ) [ 0 ] <= 239
687
695
}
688
696
@@ -727,8 +735,9 @@ impl Ipv4Addr {
727
735
/// assert_eq!(Ipv4Addr::new(203, 0, 113, 6).is_documentation(), true);
728
736
/// assert_eq!(Ipv4Addr::new(193, 34, 17, 19).is_documentation(), false);
729
737
/// ```
738
+ #[ rustc_const_stable( feature = "const_ipv4" , since = "1.48.0" ) ]
730
739
#[ stable( since = "1.7.0" , feature = "ip_17" ) ]
731
- pub fn is_documentation ( & self ) -> bool {
740
+ pub const fn is_documentation ( & self ) -> bool {
732
741
match self . octets ( ) {
733
742
[ 192 , 0 , 2 , _] => true ,
734
743
[ 198 , 51 , 100 , _] => true ,
0 commit comments