Skip to content

Commit 87dcbca

Browse files
committed
add From<[u8; n]> impls for IpAddr
1 parent c81c1d6 commit 87dcbca

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/libstd/net/ip.rs

+22
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,13 @@ impl From<[u8; 4]> for Ipv4Addr {
656656
}
657657
}
658658

659+
#[stable(feature = "ip_from_slice", since = "1.17.0")]
660+
impl From<[u8; 4]> for IpAddr {
661+
fn from(octets: [u8; 4]) -> IpAddr {
662+
IpAddr::V4(Ipv4Addr::from(octets))
663+
}
664+
}
665+
659666
impl Ipv6Addr {
660667
/// Creates a new IPv6 address from eight 16-bit segments.
661668
///
@@ -1166,6 +1173,21 @@ impl From<[u16; 8]> for Ipv6Addr {
11661173
}
11671174
}
11681175

1176+
1177+
#[stable(feature = "ip_from_slice", since = "1.17.0")]
1178+
impl From<[u8; 16]> for IpAddr {
1179+
fn from(octets: [u8; 16]) -> IpAddr {
1180+
IpAddr::V6(Ipv6Addr::from(octets))
1181+
}
1182+
}
1183+
1184+
#[stable(feature = "ip_from_slice", since = "1.17.0")]
1185+
impl From<[u16; 8]> for IpAddr {
1186+
fn from(octets: [u16; 8]) -> IpAddr {
1187+
IpAddr::V6(Ipv6Addr::from(octets))
1188+
}
1189+
}
1190+
11691191
// Tests for this module
11701192
#[cfg(all(test, not(target_os = "emscripten")))]
11711193
mod tests {

0 commit comments

Comments
 (0)