-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for ip_as_octets
#137259
Labels
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Comments
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Feb 21, 2025
libcore/net: `IpAddr::as_octets()` [ACP](rust-lang/libs-team#535) [Tracking issue](rust-lang#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.)
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Feb 21, 2025
Rollup merge of rust-lang#136609 - mammothbane:master, r=scottmcm libcore/net: `IpAddr::as_octets()` [ACP](rust-lang/libs-team#535) [Tracking issue](rust-lang#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.)
github-actions bot
pushed a commit
to tautschnig/verify-rust-std
that referenced
this issue
Mar 11, 2025
libcore/net: `IpAddr::as_octets()` [ACP](rust-lang/libs-team#535) [Tracking issue](rust-lang#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.)
github-actions bot
pushed a commit
to tautschnig/verify-rust-std
that referenced
this issue
Mar 11, 2025
libcore/net: `IpAddr::as_octets()` [ACP](rust-lang/libs-team#535) [Tracking issue](rust-lang#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.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Feature gate:
#![feature(ip_as_octets)]
This is a tracking issue for enabling reference access to
IpAddr
,Ipv4Addr
, andIpv6Addr
contents. Previously, only an array copy was exposed via.octets()
.Public API
Steps / History
core::net::Ip*Addr
octet bytes,impl AsRef<[u8]> for core::net::Ip*Addr
libs-team#535IpAddr::as_octets()
#136609Unresolved Questions
#[repr(transparent)]
for these types and document layout stability, leaving transmutation to a byte slice to third-party libraries.The text was updated successfully, but these errors were encountered: