Skip to content

Commit

Permalink
add From<[u8; n]> impls for IpAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jan 28, 2017
1 parent c81c1d6 commit 87dcbca
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/libstd/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,13 @@ impl From<[u8; 4]> for Ipv4Addr {
}
}

#[stable(feature = "ip_from_slice", since = "1.17.0")]
impl From<[u8; 4]> for IpAddr {
fn from(octets: [u8; 4]) -> IpAddr {
IpAddr::V4(Ipv4Addr::from(octets))
}
}

impl Ipv6Addr {
/// Creates a new IPv6 address from eight 16-bit segments.
///
Expand Down Expand Up @@ -1166,6 +1173,21 @@ impl From<[u16; 8]> for Ipv6Addr {
}
}


#[stable(feature = "ip_from_slice", since = "1.17.0")]
impl From<[u8; 16]> for IpAddr {
fn from(octets: [u8; 16]) -> IpAddr {
IpAddr::V6(Ipv6Addr::from(octets))
}
}

#[stable(feature = "ip_from_slice", since = "1.17.0")]
impl From<[u16; 8]> for IpAddr {
fn from(octets: [u16; 8]) -> IpAddr {
IpAddr::V6(Ipv6Addr::from(octets))
}
}

// Tests for this module
#[cfg(all(test, not(target_os = "emscripten")))]
mod tests {
Expand Down

0 comments on commit 87dcbca

Please sign in to comment.