@@ -372,7 +372,7 @@ impl IpAddr {
372
372
/// Create a new IpAddr that contains an IPv4 address.
373
373
///
374
374
/// The result will represent the IP address a.b.c.d
375
- pub fn new_v4 ( a : u8 , b : u8 , c : u8 , d : u8 ) -> IpAddr {
375
+ pub const fn new_v4 ( a : u8 , b : u8 , c : u8 , d : u8 ) -> IpAddr {
376
376
IpAddr :: V4 ( Ipv4Addr :: new ( a, b, c, d) )
377
377
}
378
378
@@ -381,7 +381,7 @@ impl IpAddr {
381
381
/// The result will represent the IP address a:b:c:d:e:f
382
382
#[ allow( clippy:: many_single_char_names) ]
383
383
#[ allow( clippy:: too_many_arguments) ]
384
- pub fn new_v6 ( a : u16 , b : u16 , c : u16 , d : u16 , e : u16 , f : u16 , g : u16 , h : u16 ) -> IpAddr {
384
+ pub const fn new_v6 ( a : u16 , b : u16 , c : u16 , d : u16 , e : u16 , f : u16 , g : u16 , h : u16 ) -> IpAddr {
385
385
IpAddr :: V6 ( Ipv6Addr :: new ( a, b, c, d, e, f, g, h) )
386
386
}
387
387
@@ -420,11 +420,11 @@ pub struct Ipv4Addr(pub libc::in_addr);
420
420
421
421
impl Ipv4Addr {
422
422
#[ allow( clippy:: identity_op) ] // More readable this way
423
- pub fn new ( a : u8 , b : u8 , c : u8 , d : u8 ) -> Ipv4Addr {
424
- let ip = ( ( u32 :: from ( a ) << 24 ) |
425
- ( u32 :: from ( b ) << 16 ) |
426
- ( u32 :: from ( c ) << 8 ) |
427
- ( u32 :: from ( d ) << 0 ) ) . to_be ( ) ;
423
+ pub const fn new ( a : u8 , b : u8 , c : u8 , d : u8 ) -> Ipv4Addr {
424
+ let ip = ( ( ( a as u32 ) << 24 ) |
425
+ ( ( b as u32 ) << 16 ) |
426
+ ( ( c as u32 ) << 8 ) |
427
+ ( ( d as u32 ) << 0 ) ) . to_be ( ) ;
428
428
429
429
Ipv4Addr ( libc:: in_addr { s_addr : ip } )
430
430
}
@@ -436,16 +436,16 @@ impl Ipv4Addr {
436
436
Ipv4Addr :: new ( bits[ 0 ] , bits[ 1 ] , bits[ 2 ] , bits[ 3 ] )
437
437
}
438
438
439
- pub fn any ( ) -> Ipv4Addr {
439
+ pub const fn any ( ) -> Ipv4Addr {
440
440
Ipv4Addr ( libc:: in_addr { s_addr : libc:: INADDR_ANY } )
441
441
}
442
442
443
- pub fn octets ( self ) -> [ u8 ; 4 ] {
443
+ pub const fn octets ( self ) -> [ u8 ; 4 ] {
444
444
let bits = u32:: from_be ( self . 0 . s_addr ) ;
445
445
[ ( bits >> 24 ) as u8 , ( bits >> 16 ) as u8 , ( bits >> 8 ) as u8 , bits as u8 ]
446
446
}
447
447
448
- pub fn to_std ( self ) -> net:: Ipv4Addr {
448
+ pub const fn to_std ( self ) -> net:: Ipv4Addr {
449
449
let bits = self . octets ( ) ;
450
450
net:: Ipv4Addr :: new ( bits[ 0 ] , bits[ 1 ] , bits[ 2 ] , bits[ 3 ] )
451
451
}
@@ -486,7 +486,7 @@ macro_rules! to_u16_array {
486
486
impl Ipv6Addr {
487
487
#[ allow( clippy:: many_single_char_names) ]
488
488
#[ allow( clippy:: too_many_arguments) ]
489
- pub fn new ( a : u16 , b : u16 , c : u16 , d : u16 , e : u16 , f : u16 , g : u16 , h : u16 ) -> Ipv6Addr {
489
+ pub const fn new ( a : u16 , b : u16 , c : u16 , d : u16 , e : u16 , f : u16 , g : u16 , h : u16 ) -> Ipv6Addr {
490
490
Ipv6Addr ( libc:: in6_addr { s6_addr : to_u8_array ! ( a, b, c, d, e, f, g, h) } )
491
491
}
492
492
@@ -496,11 +496,11 @@ impl Ipv6Addr {
496
496
}
497
497
498
498
/// Return the eight 16-bit segments that make up this address
499
- pub fn segments ( & self ) -> [ u16 ; 8 ] {
499
+ pub const fn segments ( & self ) -> [ u16 ; 8 ] {
500
500
to_u16_array ! ( self , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 )
501
501
}
502
502
503
- pub fn to_std ( & self ) -> net:: Ipv6Addr {
503
+ pub const fn to_std ( & self ) -> net:: Ipv6Addr {
504
504
let s = self . segments ( ) ;
505
505
net:: Ipv6Addr :: new ( s[ 0 ] , s[ 1 ] , s[ 2 ] , s[ 3 ] , s[ 4 ] , s[ 5 ] , s[ 6 ] , s[ 7 ] )
506
506
}
@@ -913,11 +913,11 @@ pub mod netlink {
913
913
NetlinkAddr ( addr)
914
914
}
915
915
916
- pub fn pid ( & self ) -> u32 {
916
+ pub const fn pid ( & self ) -> u32 {
917
917
self . 0 . nl_pid
918
918
}
919
919
920
- pub fn groups ( & self ) -> u32 {
920
+ pub const fn groups ( & self ) -> u32 {
921
921
self . 0 . nl_groups
922
922
}
923
923
}
@@ -1020,7 +1020,7 @@ pub mod sys_control {
1020
1020
pub struct SysControlAddr ( pub libc:: sockaddr_ctl ) ;
1021
1021
1022
1022
impl SysControlAddr {
1023
- pub fn new ( id : u32 , unit : u32 ) -> SysControlAddr {
1023
+ pub const fn new ( id : u32 , unit : u32 ) -> SysControlAddr {
1024
1024
let addr = libc:: sockaddr_ctl {
1025
1025
sc_len : mem:: size_of :: < libc:: sockaddr_ctl > ( ) as c_uchar ,
1026
1026
sc_family : AddressFamily :: System as c_uchar ,
@@ -1047,11 +1047,11 @@ pub mod sys_control {
1047
1047
Ok ( SysControlAddr :: new ( info. ctl_id , unit) )
1048
1048
}
1049
1049
1050
- pub fn id ( & self ) -> u32 {
1050
+ pub const fn id ( & self ) -> u32 {
1051
1051
self . 0 . sc_id
1052
1052
}
1053
1053
1054
- pub fn unit ( & self ) -> u32 {
1054
+ pub const fn unit ( & self ) -> u32 {
1055
1055
self . 0 . sc_unit
1056
1056
}
1057
1057
}
0 commit comments