Skip to content

Commit 3ba09b9

Browse files
committed
core/net: ip addr AsRef
1 parent 8d1e3a7 commit 3ba09b9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

library/core/src/net/ip_addr.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,22 @@ impl From<[u8; 4]> for IpAddr {
12721272
}
12731273
}
12741274

1275+
#[stable(feature = "ip_as_ref", since = "CURRENT_RUSTC_VERSION")]
1276+
impl AsRef<[u8]> for IpAddr {
1277+
#[inline]
1278+
fn as_ref(&self) -> &[u8] {
1279+
self.as_slice()
1280+
}
1281+
}
1282+
1283+
#[stable(feature = "ip_as_ref", since = "CURRENT_RUSTC_VERSION")]
1284+
impl AsRef<[u8]> for Ipv4Addr {
1285+
#[inline]
1286+
fn as_ref(&self) -> &[u8] {
1287+
self.as_slice()
1288+
}
1289+
}
1290+
12751291
impl Ipv6Addr {
12761292
/// Creates a new IPv6 address from eight 16-bit segments.
12771293
///
@@ -2332,6 +2348,14 @@ impl From<[u16; 8]> for IpAddr {
23322348
}
23332349
}
23342350

2351+
#[stable(feature = "ip_as_ref", since = "CURRENT_RUSTC_VERSION")]
2352+
impl AsRef<[u8]> for Ipv6Addr {
2353+
#[inline]
2354+
fn as_ref(&self) -> &[u8] {
2355+
self.as_slice()
2356+
}
2357+
}
2358+
23352359
#[stable(feature = "ip_bitops", since = "1.75.0")]
23362360
impl Not for Ipv4Addr {
23372361
type Output = Ipv4Addr;

0 commit comments

Comments
 (0)