-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Make all methods of std::net::Ipv4Addr
const
#76142
Conversation
Constify the following methods of `std::net::Ipv4Addr`: - `octets` - `is_loopback` - `is_private` - `is_link_local` - `is_shared` - `is_ietf_protocol_assignment` - `is_benchmarking` - `is_multicast` - `is_documentation` Also insta-stabilizes these methods as const. Possible because of the stabilization of const integer arithmetic and control flow.
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @KodrAus (Needs FCP) |
Maybe these could be made |
That is also possible, I was going over all methods of I will open a tracking issue soon to provide an overview, with that we could decide what the best path forward is. |
I think we should see if anyone on the libs team actually has an issue with these becoming |
Opened #76205. Made the methods unstable const under |
Tests added. I was working on the followup PR with the methods that require a change in implentation to make const. However now that this PR no longer makes everything also stable, I think I'm just going to include those changes here. |
Makes the following methods of `std::net::Ipv4Addr` unstable const under the `const_ipv4` feature: - `is_global` - `is_reserved` - `is_broadcast` - `to_ipv6_compatible` - `to_ipv6_mapped` This results in all methods of `Ipv4Addr` being const. Also adds tests for these methods in a const context.
std::net::Ipv4Addr
const
let [a, b, c, d] = self.octets(); | ||
Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, a, b, c, d]) | ||
Ipv6Addr { | ||
inner: c::in6_addr { s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, a, b, c, d] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the prettiest solution, using implementation details from Ipv6Addr
. Considered adding a non-pub method from_octets
to Ipv6Addr
, but it seemed out of place.
Updated the title and PR description to accurately reflect that this now covers all methods of |
LGTM! Someone pointed out to me on Zulip that we should be using unit tests in the standard library as opposed to UI tests for these, so let's do that in the future. They're a bit faster than a @bors r+ rollup |
📌 Commit 0c77257 has been approved by |
Rollup of 12 pull requests Successful merges: - rust-lang#75150 (Add a note for Ipv4Addr::to_ipv6_compatible) - rust-lang#76120 (Add `[T; N]::as_[mut_]slice`) - rust-lang#76142 (Make all methods of `std::net::Ipv4Addr` const) - rust-lang#76164 (Link to slice pattern in array docs) - rust-lang#76167 (Replace MinGW library hack with heuristic controlling link mode) - rust-lang#76204 (Rename and expose LoopState as ControlFlow) - rust-lang#76238 (Move to intra-doc links for library/core/src/iter/traits/iterator.rs) - rust-lang#76242 (Read: adjust a FIXME reference) - rust-lang#76243 (Fix typos in vec try_reserve(_exact) docs) - rust-lang#76245 (inliner: Avoid query cycles when optimizing generators) - rust-lang#76255 (Update books) - rust-lang#76261 (Use intra-doc links in `core::marker`) Failed merges: r? @ghost
Make delegation methods of `std::net::IpAddr` unstably const Make the following methods of `std::net::IpAddr` unstable const under the `const_ip` feature: - `is_unspecified` - `is_loopback` - `is_global` - `is_multicast` Also adds a test for these methods in a const context. Possible because these methods delegate to the inner `Ipv4Addr` or `Ipv6Addr`, which were made const ([PR#76205](rust-lang#76142) and [PR#76206](rust-lang#76206)), and the recent stabilization of const control flow. Part of rust-lang#76205 r? @ecstatic-morse
Make the following methods of
std::net::Ipv4Addr
unstable const under theconst_ipv4
feature:octets
is_loopback
is_private
is_link_local
is_global
(unstable)is_shared
(unstable)is_ietf_protocol_assignment
(unstable)is_benchmarking
(unstable)is_reserved
(unstable)is_multicast
is_broadcast
is_documentation
to_ipv6_compatible
to_ipv6_mapped
This would make all methods of
Ipv6Addr
const.Of these methods,
is_global
,is_broadcast
,to_ipv6_compatible
, andto_ipv6_mapped
require a change in implementation.Part of #76205