Skip to content

Commit e9a96c0

Browse files
committed
Move IPs to assoc consts
1 parent 02c272d commit e9a96c0

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253
#![feature(compiler_builtins_lib)]
254254
#![feature(const_fn)]
255255
#![feature(const_int_ops)]
256+
#![feature(const_ip)]
256257
#![feature(core_intrinsics)]
257258
#![feature(dropck_eyepatch)]
258259
#![feature(exact_size_is_empty)]

src/libstd/net/ip.rs

+20-28
Original file line numberDiff line numberDiff line change
@@ -353,41 +353,37 @@ impl Ipv4Addr {
353353
}
354354
}
355355

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.
357357
///
358358
/// # Examples
359359
///
360360
/// ```
361361
/// #![feature(ip_constructors)]
362362
/// use std::net::Ipv4Addr;
363363
///
364-
/// let addr = Ipv4Addr::localhost();
364+
/// let addr = Ipv4Addr::LOCALHOST;
365365
/// assert_eq!(addr, Ipv4Addr::new(127, 0, 0, 1));
366366
/// ```
367367
#[unstable(feature = "ip_constructors",
368368
reason = "requires greater scrutiny before stabilization",
369369
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);
373371

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
375373
///
376374
/// # Examples
377375
///
378376
/// ```
379377
/// #![feature(ip_constructors)]
380378
/// use std::net::Ipv4Addr;
381379
///
382-
/// let addr = Ipv4Addr::unspecified();
380+
/// let addr = Ipv4Addr::UNSPECIFIED;
383381
/// assert_eq!(addr, Ipv4Addr::new(0, 0, 0, 0));
384382
/// ```
385383
#[unstable(feature = "ip_constructors",
386384
reason = "requires greater scrutiny before stabilization",
387385
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);
391387

392388
/// Returns the four eight-bit integers that make up this address.
393389
///
@@ -878,41 +874,37 @@ impl Ipv6Addr {
878874

879875
}
880876

881-
/// Creates a new IPv6 address representing localhost: `::1`.
877+
/// An IPv6 address representing localhost: `::1`.
882878
///
883879
/// # Examples
884880
///
885881
/// ```
886882
/// #![feature(ip_constructors)]
887883
/// use std::net::Ipv6Addr;
888884
///
889-
/// let addr = Ipv6Addr::localhost();
885+
/// let addr = Ipv6Addr::LOCALHOST;
890886
/// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
891887
/// ```
892888
#[unstable(feature = "ip_constructors",
893889
reason = "requires greater scrutiny before stabilization",
894890
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);
898892

899-
/// Creates a new IPv6 address representing the unspecified address: `::`
893+
/// An IPv6 address representing the unspecified address: `::`
900894
///
901895
/// # Examples
902896
///
903897
/// ```
904898
/// #![feature(ip_constructors)]
905899
/// use std::net::Ipv6Addr;
906900
///
907-
/// let addr = Ipv6Addr::unspecified();
901+
/// let addr = Ipv6Addr::UNSPECIFIED;
908902
/// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0));
909903
/// ```
910904
#[unstable(feature = "ip_constructors",
911905
reason = "requires greater scrutiny before stabilization",
912906
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);
916908

917909
/// Returns the eight 16-bit segments that make up this address.
918910
///
@@ -1854,18 +1846,18 @@ mod tests {
18541846

18551847
#[test]
18561848
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());
18611853
}
18621854

18631855
#[test]
18641856
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());
18691861
}
18701862

18711863
#[test]

0 commit comments

Comments
 (0)