mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
Rollup merge of #40590 - z1mvader:master, r=steveklabnik
documented order of conversion between u32 an ipv4addr This fixes https://github.com/rust-lang/rust/issues/40118
This commit is contained in:
@@ -636,6 +636,7 @@ fn from_inner(addr: c::in_addr) -> Ipv4Addr {
|
||||
|
||||
#[stable(feature = "ip_u32", since = "1.1.0")]
|
||||
impl From<Ipv4Addr> for u32 {
|
||||
/// It performs the conversion in network order (big-endian).
|
||||
fn from(ip: Ipv4Addr) -> u32 {
|
||||
let ip = ip.octets();
|
||||
((ip[0] as u32) << 24) + ((ip[1] as u32) << 16) + ((ip[2] as u32) << 8) + (ip[3] as u32)
|
||||
@@ -644,6 +645,7 @@ fn from(ip: Ipv4Addr) -> u32 {
|
||||
|
||||
#[stable(feature = "ip_u32", since = "1.1.0")]
|
||||
impl From<u32> for Ipv4Addr {
|
||||
/// It performs the conversion in network order (big-endian).
|
||||
fn from(ip: u32) -> Ipv4Addr {
|
||||
Ipv4Addr::new((ip >> 24) as u8, (ip >> 16) as u8, (ip >> 8) as u8, ip as u8)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user