Skip to content
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 IpvNAddr::{BITS, to_bits, from_bits} (ip_bits) #113744

Closed
4 of 5 tasks
clarfonthey opened this issue Jul 16, 2023 · 11 comments · Fixed by #125551
Closed
4 of 5 tasks

Tracking Issue for IpvNAddr::{BITS, to_bits, from_bits} (ip_bits) #113744

clarfonthey opened this issue Jul 16, 2023 · 11 comments · Fixed by #125551
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@clarfonthey
Copy link
Contributor

clarfonthey commented Jul 16, 2023

Feature gate: #![feature(ip_bits)]

This is a tracking issue for IpvNAddr::{BITS, to_bits, from_bits}.

This API exists mostly so that users can be explicit about various bit operations which are useful for computing IP networks (see ACP linked below). For example, IpvNAddr::BITS - ip.to_bits().trailing_zeros() can be used to determine the network prefix length of a given address.

Additionally, since const traits are still a long ways out, this provides a const version of the conversions to/from integers that people can use in the meantime.

Public API

impl Ipv4Addr {
    pub const BITS: u32 = 32;
    pub const fn from_bits(bits: u32) -> Ipv4Addr;
    pub const fn to_bits(self) -> u32;
}

impl Ipv6Addr {
    pub const BITS: u32 = 128;
    pub const fn from_bits(bits: u128) -> Ipv4Addr;
    pub const fn to_bits(self) -> u128;
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/api-change-proposals.html

  2. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@clarfonthey clarfonthey added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jul 16, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 22, 2023
Add BITS, from_bits, to_bits to IP addresses

ACP: rust-lang/libs-team#235
Tracking issue: rust-lang#113744
@thomcc
Copy link
Member

thomcc commented Jul 30, 2023

It would be nice to improve the docs here to be more specific about endianness, since we got questions about it in the PR after it landed.

CLEckhardt added a commit to CLEckhardt/rust that referenced this issue Dec 1, 2023
Adds explanation of how endianness is handled when converting `Ipv4Addr`
and `Ipv6Addr` to and from bits.

Addresses rust-lang#113744
CLEckhardt added a commit to CLEckhardt/rust that referenced this issue Dec 7, 2023
Adds explanation of how endianness is handled when converting `Ipv4Addr`
and `Ipv6Addr` to and from bits.

Addresses rust-lang#113744
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 8, 2023
…s, r=cuviper

Elaborate on ip_addr bit conversion endianness

Adds explanation of how endianness is handled when converting `Ipv4Addr` and `Ipv6Addr` to and from bits. This is intended to unblock stabilization of the affected methods.

Addresses rust-lang#113744
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 8, 2023
Rollup merge of rust-lang#118505 - CLEckhardt:update_ip_addr_bits_docs, r=cuviper

Elaborate on ip_addr bit conversion endianness

Adds explanation of how endianness is handled when converting `Ipv4Addr` and `Ipv6Addr` to and from bits. This is intended to unblock stabilization of the affected methods.

Addresses rust-lang#113744
@yungcomputerchair
Copy link

yungcomputerchair commented Dec 27, 2023

Is this ready for FCP now that the documentation issue has been addressed? Would love to see this stabilized.

@GrigorenkoPV
Copy link
Contributor

The docs say this:

In some cases the tracking issue may not have many other active participants, so if you're ever having trouble getting any feedback please ping one of the libs team reviewers directly to request assistance.

So I hope it is okay if I ping @cuviper. (Terribly sorry if it is not.)

@cuviper
Copy link
Member

cuviper commented Mar 1, 2024

It seems ready to me. Maybe @yungcomputerchair or @GrigorenkoPV can try writing a stabilization report?

(I don't think I can start the actual FCP since I'm not part of the libs-api team.)

@rfcbot
Copy link

rfcbot commented Mar 2, 2024

Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Mar 2, 2024
@pronebird
Copy link

pronebird commented Mar 6, 2024

Can someone please clarify, impl From<u128> for Ipv6Addr is not marked as unstable although internally it calls into Ipv6Addr::from_bits which is marked unstable. Using the From implementation just works with stable compiler but using from_bits directly prints error[E0658]: use of unstable library feature 'ip_bits'. Is it just an oversight?

@GrigorenkoPV
Copy link
Contributor

Can someone please clarify, impl From<u128> for Ipv6Addr is not marked as unstable although internally it calls into Ipv6Addr::from_bits which is marked unstable. Using the From implementation just works with stable compiler but using from_bits directly prints error[E0658]: use of unstable library feature 'ip_bits'. Is it just an oversight?

impl From<u128> for Ipv6Addr has been around since 1.26.0 and used to be implemented without using from_bits. But with the introduction of unstable from_bits the internal implementation got changed (both the compiler and the standard library do not hesitate do use unstable features internally). This affects neither the stability of the existing impl, nor its behavior, which is why this change is okay.

https://github.com/rust-lang/rust/pull/113746/files#diff-d0718870fd66d5eb2a63284de49bd959d2648c7d7fb90dfc26d9e264e700f5bdL1926-L1947

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label May 13, 2024
@rfcbot
Copy link

rfcbot commented May 13, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label May 13, 2024
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels May 23, 2024
@rfcbot
Copy link

rfcbot commented May 23, 2024

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label May 23, 2024
@Rawk
Copy link
Contributor

Rawk commented May 24, 2024

For example, IpvNAddr::BITS - ip.to_bits().trailing_zeros() can be used to determine the network prefix length of a given address.

Note that this is only true if address is a netmask. A valid network prefix can (and often does) include trailing zeroes.

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label May 24, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 28, 2024
Stabilise `IpvNAddr::{BITS, to_bits, from_bits}` (`ip_bits`)

This completed FCP in rust-lang#113744. (Closes rust-lang#113744.)

Stabilises the following APIs:

```rust
impl Ipv4Addr {
    pub const BITS: u32 = 32;
    pub const fn from_bits(bits: u32) -> Ipv4Addr;
    pub const fn to_bits(self) -> u32;
}

impl Ipv6Addr {
    pub const BITS: u32 = 128;
    pub const fn from_bits(bits: u128) -> Ipv4Addr;
    pub const fn to_bits(self) -> u128;
}
```
workingjubilee added a commit to workingjubilee/rustc that referenced this issue May 28, 2024
Stabilise `IpvNAddr::{BITS, to_bits, from_bits}` (`ip_bits`)

This completed FCP in rust-lang#113744. (Closes rust-lang#113744.)

Stabilises the following APIs:

```rust
impl Ipv4Addr {
    pub const BITS: u32 = 32;
    pub const fn from_bits(bits: u32) -> Ipv4Addr;
    pub const fn to_bits(self) -> u32;
}

impl Ipv6Addr {
    pub const BITS: u32 = 128;
    pub const fn from_bits(bits: u128) -> Ipv4Addr;
    pub const fn to_bits(self) -> u128;
}
```
@bors bors closed this as completed in 941bf8b May 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 28, 2024
Rollup merge of rust-lang#125551 - clarfonthey:ip-bits, r=jhpratt

Stabilise `IpvNAddr::{BITS, to_bits, from_bits}` (`ip_bits`)

This completed FCP in rust-lang#113744. (Closes rust-lang#113744.)

Stabilises the following APIs:

```rust
impl Ipv4Addr {
    pub const BITS: u32 = 32;
    pub const fn from_bits(bits: u32) -> Ipv4Addr;
    pub const fn to_bits(self) -> u32;
}

impl Ipv6Addr {
    pub const BITS: u32 = 128;
    pub const fn from_bits(bits: u128) -> Ipv4Addr;
    pub const fn to_bits(self) -> u128;
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants