-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Introduce private helper method in_network
for Ipv{4,6}Addr
#86969
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
Wouldn't a full mask be more efficient? By that I mean the ability to specify a mask, not just a prefix. |
What would be non-prefix based ranges? Currently the method is only intended to be used as a helper for the implementation of the other methods ( |
I think this check from another PR of yours could be expressed as a mask with a gap
|
Ah from #86634. That code should check if the address is in Edit: the code is incorrect, as written it would indeed be a mask with a gap. It should be |
I like the concept of this, but if we're going to have functionality like this, I think we should have a dedicated type for a network, with ways to construct a network with either address and mask or address and number of bits. |
I can additionally work on a public API version of this functionality. However I see this PR more as a refactoring of all the |
I opened #86992 to introduce public types representing IP prefixes. |
You can do exactly this with |
☔ The latest upstream changes (presumably #87535) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage: |
As I proposed in #86634 (comment), this PR introduces a private helper method
in_network
to check if an IP address is in a network. Checking ifaddress
is in224.0.0.0/4
would be written as:This improves readability and possibly performance (based on https://rust.godbolt.org/z/6KEGWcd5a) over the various other ways this is implemented right now:
I think it would be a good idea to eventually offer this kind of functionality publically, although with a different API. Maybe Rust could get dedicated Ipv{4,6}Network types like Python?