@@ -143,7 +143,8 @@ impl SocketAddr {
143
143
/// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
144
144
/// ```
145
145
#[ stable( feature = "ip_addr" , since = "1.7.0" ) ]
146
- pub fn ip ( & self ) -> IpAddr {
146
+ #[ rustc_const_unstable( feature = "const_socketaddr" , issue = "82485" ) ]
147
+ pub const fn ip ( & self ) -> IpAddr {
147
148
match * self {
148
149
SocketAddr :: V4 ( ref a) => IpAddr :: V4 ( * a. ip ( ) ) ,
149
150
SocketAddr :: V6 ( ref a) => IpAddr :: V6 ( * a. ip ( ) ) ,
@@ -182,7 +183,8 @@ impl SocketAddr {
182
183
/// assert_eq!(socket.port(), 8080);
183
184
/// ```
184
185
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
185
- pub fn port ( & self ) -> u16 {
186
+ #[ rustc_const_unstable( feature = "const_socketaddr" , issue = "82485" ) ]
187
+ pub const fn port ( & self ) -> u16 {
186
188
match * self {
187
189
SocketAddr :: V4 ( ref a) => a. port ( ) ,
188
190
SocketAddr :: V6 ( ref a) => a. port ( ) ,
@@ -224,7 +226,8 @@ impl SocketAddr {
224
226
/// assert_eq!(socket.is_ipv6(), false);
225
227
/// ```
226
228
#[ stable( feature = "sockaddr_checker" , since = "1.16.0" ) ]
227
- pub fn is_ipv4 ( & self ) -> bool {
229
+ #[ rustc_const_unstable( feature = "const_socketaddr" , issue = "82485" ) ]
230
+ pub const fn is_ipv4 ( & self ) -> bool {
228
231
matches ! ( * self , SocketAddr :: V4 ( _) )
229
232
}
230
233
@@ -244,7 +247,8 @@ impl SocketAddr {
244
247
/// assert_eq!(socket.is_ipv6(), true);
245
248
/// ```
246
249
#[ stable( feature = "sockaddr_checker" , since = "1.16.0" ) ]
247
- pub fn is_ipv6 ( & self ) -> bool {
250
+ #[ rustc_const_unstable( feature = "const_socketaddr" , issue = "82485" ) ]
251
+ pub const fn is_ipv6 ( & self ) -> bool {
248
252
matches ! ( * self , SocketAddr :: V6 ( _) )
249
253
}
250
254
}
@@ -284,7 +288,8 @@ impl SocketAddrV4 {
284
288
/// assert_eq!(socket.ip(), &Ipv4Addr::new(127, 0, 0, 1));
285
289
/// ```
286
290
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
287
- pub fn ip ( & self ) -> & Ipv4Addr {
291
+ #[ rustc_const_unstable( feature = "const_socketaddr" , issue = "82485" ) ]
292
+ pub const fn ip ( & self ) -> & Ipv4Addr {
288
293
// SAFETY: `Ipv4Addr` is `#[repr(C)] struct { _: in_addr; }`.
289
294
// It is safe to cast from `&in_addr` to `&Ipv4Addr`.
290
295
unsafe { & * ( & self . inner . sin_addr as * const c:: in_addr as * const Ipv4Addr ) }
@@ -317,7 +322,8 @@ impl SocketAddrV4 {
317
322
/// assert_eq!(socket.port(), 8080);
318
323
/// ```
319
324
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
320
- pub fn port ( & self ) -> u16 {
325
+ #[ rustc_const_unstable( feature = "const_socketaddr" , issue = "82485" ) ]
326
+ pub const fn port ( & self ) -> u16 {
321
327
ntohs ( self . inner . sin_port )
322
328
}
323
329
@@ -380,7 +386,8 @@ impl SocketAddrV6 {
380
386
/// assert_eq!(socket.ip(), &Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
381
387
/// ```
382
388
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
383
- pub fn ip ( & self ) -> & Ipv6Addr {
389
+ #[ rustc_const_unstable( feature = "const_socketaddr" , issue = "82485" ) ]
390
+ pub const fn ip ( & self ) -> & Ipv6Addr {
384
391
unsafe { & * ( & self . inner . sin6_addr as * const c:: in6_addr as * const Ipv6Addr ) }
385
392
}
386
393
@@ -411,7 +418,8 @@ impl SocketAddrV6 {
411
418
/// assert_eq!(socket.port(), 8080);
412
419
/// ```
413
420
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
414
- pub fn port ( & self ) -> u16 {
421
+ #[ rustc_const_unstable( feature = "const_socketaddr" , issue = "82485" ) ]
422
+ pub const fn port ( & self ) -> u16 {
415
423
ntohs ( self . inner . sin6_port )
416
424
}
417
425
@@ -452,7 +460,8 @@ impl SocketAddrV6 {
452
460
/// assert_eq!(socket.flowinfo(), 10);
453
461
/// ```
454
462
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
455
- pub fn flowinfo ( & self ) -> u32 {
463
+ #[ rustc_const_unstable( feature = "const_socketaddr" , issue = "82485" ) ]
464
+ pub const fn flowinfo ( & self ) -> u32 {
456
465
self . inner . sin6_flowinfo
457
466
}
458
467
@@ -490,7 +499,8 @@ impl SocketAddrV6 {
490
499
/// assert_eq!(socket.scope_id(), 78);
491
500
/// ```
492
501
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
493
- pub fn scope_id ( & self ) -> u32 {
502
+ #[ rustc_const_unstable( feature = "const_socketaddr" , issue = "82485" ) ]
503
+ pub const fn scope_id ( & self ) -> u32 {
494
504
self . inner . sin6_scope_id
495
505
}
496
506
0 commit comments