@@ -353,41 +353,37 @@ impl Ipv4Addr {
353
353
}
354
354
}
355
355
356
- /// Creates a new IPv4 address with the address pointing to localhost: 127.0.0.1.
356
+ /// An IPv4 address with the address pointing to localhost: 127.0.0.1.
357
357
///
358
358
/// # Examples
359
359
///
360
360
/// ```
361
361
/// #![feature(ip_constructors)]
362
362
/// use std::net::Ipv4Addr;
363
363
///
364
- /// let addr = Ipv4Addr::localhost() ;
364
+ /// let addr = Ipv4Addr::LOCALHOST ;
365
365
/// assert_eq!(addr, Ipv4Addr::new(127, 0, 0, 1));
366
366
/// ```
367
367
#[ unstable( feature = "ip_constructors" ,
368
368
reason = "requires greater scrutiny before stabilization" ,
369
369
issue = "44582" ) ]
370
- pub fn localhost ( ) -> Ipv4Addr {
371
- Ipv4Addr :: new ( 127 , 0 , 0 , 1 )
372
- }
370
+ pub const LOCALHOST : Self = Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ;
373
371
374
- /// Creates a new IPv4 address representing an unspecified address: 0.0.0.0
372
+ /// An IPv4 address representing an unspecified address: 0.0.0.0
375
373
///
376
374
/// # Examples
377
375
///
378
376
/// ```
379
377
/// #![feature(ip_constructors)]
380
378
/// use std::net::Ipv4Addr;
381
379
///
382
- /// let addr = Ipv4Addr::unspecified() ;
380
+ /// let addr = Ipv4Addr::UNSPECIFIED ;
383
381
/// assert_eq!(addr, Ipv4Addr::new(0, 0, 0, 0));
384
382
/// ```
385
383
#[ unstable( feature = "ip_constructors" ,
386
384
reason = "requires greater scrutiny before stabilization" ,
387
385
issue = "44582" ) ]
388
- pub fn unspecified ( ) -> Ipv4Addr {
389
- Ipv4Addr :: new ( 0 , 0 , 0 , 0 )
390
- }
386
+ pub const UNSPECIFIED : Self = Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) ;
391
387
392
388
/// Returns the four eight-bit integers that make up this address.
393
389
///
@@ -878,41 +874,37 @@ impl Ipv6Addr {
878
874
879
875
}
880
876
881
- /// Creates a new IPv6 address representing localhost: `::1`.
877
+ /// An IPv6 address representing localhost: `::1`.
882
878
///
883
879
/// # Examples
884
880
///
885
881
/// ```
886
882
/// #![feature(ip_constructors)]
887
883
/// use std::net::Ipv6Addr;
888
884
///
889
- /// let addr = Ipv6Addr::localhost() ;
885
+ /// let addr = Ipv6Addr::LOCALHOST ;
890
886
/// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
891
887
/// ```
892
888
#[ unstable( feature = "ip_constructors" ,
893
889
reason = "requires greater scrutiny before stabilization" ,
894
890
issue = "44582" ) ]
895
- pub fn localhost ( ) -> Ipv6Addr {
896
- Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 )
897
- }
891
+ pub const LOCALHOST : Self = Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) ;
898
892
899
- /// Creates a new IPv6 address representing the unspecified address: `::`
893
+ /// An IPv6 address representing the unspecified address: `::`
900
894
///
901
895
/// # Examples
902
896
///
903
897
/// ```
904
898
/// #![feature(ip_constructors)]
905
899
/// use std::net::Ipv6Addr;
906
900
///
907
- /// let addr = Ipv6Addr::unspecified() ;
901
+ /// let addr = Ipv6Addr::UNSPECIFIED ;
908
902
/// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0));
909
903
/// ```
910
904
#[ unstable( feature = "ip_constructors" ,
911
905
reason = "requires greater scrutiny before stabilization" ,
912
906
issue = "44582" ) ]
913
- pub fn unspecified ( ) -> Ipv6Addr {
914
- Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
915
- }
907
+ pub const UNSPECIFIED : Self = Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ;
916
908
917
909
/// Returns the eight 16-bit segments that make up this address.
918
910
///
@@ -1854,18 +1846,18 @@ mod tests {
1854
1846
1855
1847
#[ test]
1856
1848
fn ipv4_from_constructors ( ) {
1857
- assert_eq ! ( Ipv4Addr :: localhost ( ) , Ipv4Addr :: new( 127 , 0 , 0 , 1 ) ) ;
1858
- assert ! ( Ipv4Addr :: localhost ( ) . is_loopback( ) ) ;
1859
- assert_eq ! ( Ipv4Addr :: unspecified ( ) , Ipv4Addr :: new( 0 , 0 , 0 , 0 ) ) ;
1860
- assert ! ( Ipv4Addr :: unspecified ( ) . is_unspecified( ) ) ;
1849
+ assert_eq ! ( Ipv4Addr :: LOCALHOST , Ipv4Addr :: new( 127 , 0 , 0 , 1 ) ) ;
1850
+ assert ! ( Ipv4Addr :: LOCALHOST . is_loopback( ) ) ;
1851
+ assert_eq ! ( Ipv4Addr :: UNSPECIFIED , Ipv4Addr :: new( 0 , 0 , 0 , 0 ) ) ;
1852
+ assert ! ( Ipv4Addr :: UNSPECIFIED . is_unspecified( ) ) ;
1861
1853
}
1862
1854
1863
1855
#[ test]
1864
1856
fn ipv6_from_contructors ( ) {
1865
- assert_eq ! ( Ipv6Addr :: localhost ( ) , Ipv6Addr :: new( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) ) ;
1866
- assert ! ( Ipv6Addr :: localhost ( ) . is_loopback( ) ) ;
1867
- assert_eq ! ( Ipv6Addr :: unspecified ( ) , Ipv6Addr :: new( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ) ;
1868
- assert ! ( Ipv6Addr :: unspecified ( ) . is_unspecified( ) ) ;
1857
+ assert_eq ! ( Ipv6Addr :: LOCALHOST , Ipv6Addr :: new( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) ) ;
1858
+ assert ! ( Ipv6Addr :: LOCALHOST . is_loopback( ) ) ;
1859
+ assert_eq ! ( Ipv6Addr :: UNSPECIFIED , Ipv6Addr :: new( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ) ;
1860
+ assert ! ( Ipv6Addr :: UNSPECIFIED . is_unspecified( ) ) ;
1869
1861
}
1870
1862
1871
1863
#[ test]
0 commit comments