diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2019-02-10 21:45:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-10 21:45:08 +0100 |
| commit | d9f97809187e4830ceedc00ed32467c252ff48f2 (patch) | |
| tree | 6aca53036c01fd6be4677f89a8fb0556cdf9d27b /src/libstd/net | |
| parent | e917f8b53150978efede7e623b3ce8be5810bf2a (diff) | |
| parent | 87f5a98a5d8f29d1a631cd06a39863a1e494b4d7 (diff) | |
| download | rust-d9f97809187e4830ceedc00ed32467c252ff48f2.tar.gz rust-d9f97809187e4830ceedc00ed32467c252ff48f2.zip | |
Rollup merge of #57740 - JakubOnderka:ipv4addr-to_ne_bytes, r=scottmcm
Use `to_ne_bytes` for converting IPv4Addr to octets It is easier and it should be also faster, because [`to_ne_bytes`](https://doc.rust-lang.org/std/primitive.u32.html#method.to_ne_bytes) just calls `mem::transmute`.
Diffstat (limited to 'src/libstd/net')
| -rw-r--r-- | src/libstd/net/ip.rs | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index f45cd8b8c10..4e064672fbc 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -392,8 +392,7 @@ impl Ipv4Addr { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn octets(&self) -> [u8; 4] { - let bits = u32::from_be(self.inner.s_addr); - [(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8] + self.inner.s_addr.to_ne_bytes() } /// Returns [`true`] for the special 'unspecified' address (0.0.0.0). |
