diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-21 19:01:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-21 19:01:13 +0100 |
| commit | 4aa973b3e43a810cc0f37a182da22feb80d73e81 (patch) | |
| tree | a2dd1dd13263e79fbd4c5c4b2b9466c6c7a407da /compiler/rustc_codegen_llvm/src | |
| parent | 28164f1229e02856070e61644c0f44ea39658fba (diff) | |
| parent | 8fb888555fb54dfd39529bca6f1180c083bfe36f (diff) | |
| download | rust-4aa973b3e43a810cc0f37a182da22feb80d73e81.tar.gz rust-4aa973b3e43a810cc0f37a182da22feb80d73e81.zip | |
Rollup merge of #136609 - mammothbane:master, r=scottmcm
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.)
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions
