![]() libcore/net: `IpAddr::as_octets()` [ACP](https://github.com/rust-lang/libs-team/issues/535) [Tracking issue](https://github.com/rust-lang/rust/issues/137259) Adds `const` `core::net::IpAddr{,v4,v6}::as_octets()` methods to provide reference access to IP address contents. The concrete usecase for me is allowing the `IpAddr` to provide an extended lifetime in contexts that want a `&[u8]`: ```rust trait AddrSlice { fn addr_slice(&self) -> &[u8]; } impl AddrSlice for IpAddrV4 { fn addr_slice(&self) -> &[u8] { // self.octets() doesn't help us here, because we can't return a reference to the owned array. // Instead we want the IpAddrV4 to continue owning the memory: self.as_octets() } } ``` (Notably, in this case we can't parameterize `AddrSlice` by a `const N: usize` (such that `fn addr_slice(&self) -> [u8; N]`) and maintain object-safety.) |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |