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

Open
3 of 5 tasks
clarfonthey opened this issue Jul 16, 2023 · 8 comments
Open
3 of 5 tasks

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

clarfonthey opened this issue Jul 16, 2023 · 8 comments
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. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. 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

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. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants