Tracking Issue for ip_as_octets
· Issue #137259 · rust-lang/rust (original) (raw)
Feature gate: #![feature(ip_as_octets)]
This is a tracking issue for enabling reference access to IpAddr
, Ipv4Addr
, and Ipv6Addr
contents. Previously, only an array copy was exposed via .octets()
.
Public API
impl core:🥅:IpAddr { pub const fn as_octets(&self) -> &[u8]; }
impl core:🥅:Ipv4Addr { pub const fn as_octets(&self) -> &[u8; 4]; }
impl core:🥅:Ipv6Addr { pub const fn as_octets(&self) -> &[u8; 16]; }
Steps / History
- ACP: ref access to core:🥅:Ip*Addr octet bytes, impl AsRef<[u8]> for core:🥅:Ip*Addr libs-team#535
- Implementation: libcore/net: IpAddr::as_octets() #136609
- Final comment period (FCP)
- Stabilization PR
Unresolved Questions
- @tgross35 offered a potential alternative in the ACP: that we instead provide
#[repr(transparent)]
for these types and document layout stability, leaving transmutation to a byte slice to third-party libraries.