Use to_ne_bytes for converting IPv4Address to octets
It is easier and it should be also faster, because `to_ne_bytes` just calls `mem::transmute`.
This commit is contained in:
parent
527b8d4243
commit
87f5a98a5d
1 changed files with 1 additions and 2 deletions
|
|
@ -393,8 +393,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).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue