diff options
| author | bors <bors@rust-lang.org> | 2017-09-17 01:51:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-09-17 01:51:55 +0000 |
| commit | 71e37674a1f1f876003c308429cc1ef4d15edf87 (patch) | |
| tree | aa0010f1e01317cbc540f2e38c0b6371c09fce3c /src/libstd | |
| parent | b492405b1fcfb8243481582182a0232fb5177021 (diff) | |
| parent | 2bd4dcf891d9cfe567c607fa8607f46b212b1aa3 (diff) | |
| download | rust-71e37674a1f1f876003c308429cc1ef4d15edf87.tar.gz rust-71e37674a1f1f876003c308429cc1ef4d15edf87.zip | |
Auto merge of #44634 - alexcrichton:rollup, r=alexcrichton
Rollup of 19 pull requests - Successful merges: #44273, #44356, #44395, #44531, #44537, #44542, #44560, #44567, #44574, #44577, #44586, #44589, #44590, #44593, #44598, #44606, #44609, #44616, #44631 - Failed merges:
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 3 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 3 | ||||
| -rw-r--r-- | src/libstd/net/ip.rs | 90 |
3 files changed, 95 insertions, 1 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index fbb69ca9749..96af2272578 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -588,6 +588,9 @@ impl<K, V, S> HashMap<K, V, S> impl<K: Hash + Eq, V> HashMap<K, V, RandomState> { /// Creates an empty `HashMap`. /// + /// The hash map is initially created with a capacity of 0, so it will not allocate until it + /// is first inserted into. + /// /// # Examples /// /// ``` diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 9771363d545..51698ce7c17 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -125,6 +125,9 @@ pub struct HashSet<T, S = RandomState> { impl<T: Hash + Eq> HashSet<T, RandomState> { /// Creates an empty `HashSet`. /// + /// The hash set is initially created with a capacity of 0, so it will not allocate until it + /// is first inserted into. + /// /// # Examples /// /// ``` diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index 0abf8179cc9..eea604943af 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -10,7 +10,7 @@ #![unstable(feature = "ip", reason = "extra functionality has not been \ scrutinized to the level that it should \ - be stable", + be to be stable", issue = "27709")] use cmp::Ordering; @@ -342,6 +342,42 @@ impl Ipv4Addr { } } + /// Creates a new IPv4 address with the address pointing to localhost: 127.0.0.1. + /// + /// # Examples + /// + /// ``` + /// #![feature(ip_constructors)] + /// use std::net::Ipv4Addr; + /// + /// let addr = Ipv4Addr::localhost(); + /// assert_eq!(addr, Ipv4Addr::new(127, 0, 0, 1)); + /// ``` + #[unstable(feature = "ip_constructors", + reason = "requires greater scrutiny before stabilization", + issue = "44582")] + pub fn localhost() -> Ipv4Addr { + Ipv4Addr::new(127, 0, 0, 1) + } + + /// Creates a new IPv4 address representing an unspecified address: 0.0.0.0 + /// + /// # Examples + /// + /// ``` + /// #![feature(ip_constructors)] + /// use std::net::Ipv4Addr; + /// + /// let addr = Ipv4Addr::unspecified(); + /// assert_eq!(addr, Ipv4Addr::new(0, 0, 0, 0)); + /// ``` + #[unstable(feature = "ip_constructors", + reason = "requires greater scrutiny before stabilization", + issue = "44582")] + pub fn unspecified() -> Ipv4Addr { + Ipv4Addr::new(0, 0, 0, 0) + } + /// Returns the four eight-bit integers that make up this address. /// /// # Examples @@ -788,6 +824,42 @@ impl Ipv6Addr { Ipv6Addr { inner: addr } } + /// Creates a new IPv6 address representing localhost: `::1`. + /// + /// # Examples + /// + /// ``` + /// #![feature(ip_constructors)] + /// use std::net::Ipv6Addr; + /// + /// let addr = Ipv6Addr::localhost(); + /// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); + /// ``` + #[unstable(feature = "ip_constructors", + reason = "requires greater scrutiny before stabilization", + issue = "44582")] + pub fn localhost() -> Ipv6Addr { + Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1) + } + + /// Creates a new IPv6 address representing the unspecified address: `::` + /// + /// # Examples + /// + /// ``` + /// #![feature(ip_constructors)] + /// use std::net::Ipv6Addr; + /// + /// let addr = Ipv6Addr::unspecified(); + /// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)); + /// ``` + #[unstable(feature = "ip_constructors", + reason = "requires greater scrutiny before stabilization", + issue = "44582")] + pub fn unspecified() -> Ipv6Addr { + Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0) + } + /// Returns the eight 16-bit segments that make up this address. /// /// # Examples @@ -1682,6 +1754,22 @@ mod tests { } #[test] + fn ipv4_from_constructors() { + assert_eq!(Ipv4Addr::localhost(), Ipv4Addr::new(127, 0, 0, 1)); + assert!(Ipv4Addr::localhost().is_loopback()); + assert_eq!(Ipv4Addr::unspecified(), Ipv4Addr::new(0, 0, 0, 0)); + assert!(Ipv4Addr::unspecified().is_unspecified()); + } + + #[test] + fn ipv6_from_contructors() { + assert_eq!(Ipv6Addr::localhost(), Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); + assert!(Ipv6Addr::localhost().is_loopback()); + assert_eq!(Ipv6Addr::unspecified(), Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)); + assert!(Ipv6Addr::unspecified().is_unspecified()); + } + + #[test] fn ipv4_from_octets() { assert_eq!(Ipv4Addr::from([127, 0, 0, 1]), Ipv4Addr::new(127, 0, 0, 1)) } |
