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:
Corey Farwell 2017-03-19 10:18:19 -04:00 committed by GitHub
commit d74c528f3a
1 changed files with 2 additions and 0 deletions

View File

@ -636,6 +636,7 @@ impl FromInner<c::in_addr> for 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 @@ impl From<Ipv4Addr> for 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)
}