Auto merge of #129238 - umgefahren:stabilize-ipv6-unique-local, r=dtolnay
Stabilize `Ipv6Addr::is_unique_local` and `Ipv6Addr::is_unicast_link_local`
Make `Ipv6Addr::is_unique_local` and `Ipv6Addr::is_unicast_link_local` stable (+const).
Newly stable API:
```rust
impl Ipv6Addr {
// Newly stable under `ipv6_is_unique_local`
const fn is_unique_local(&self) -> bool;
// Newly stable under `ipv6_is_unique_local`
const fn is_unicast_link_local(&self) -> bool;
}
```
These stabilise a subset of the following tracking issue:
- #27709
I have looked and could not find any issues with `is_unique_local` and `is_unicast_link_local`. There is a well received comment calling for stabilisation of the latter function.
Both functions are well defined and consistent with implementations in other languages:
- [Go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/net/netip/netip.go;l=518)
- [Python](e9d1bf353c/Lib/ipaddress.py (L2319-L2321)
)
- [Ruby (unique local)](https://ruby-doc.org/stdlib-2.5.1/libdoc/ipaddr/rdoc/IPAddr.html#private-3F-source)
- [Ruby (unicast link local)](https://ruby-doc.org/stdlib-2.5.1/libdoc/ipaddr/rdoc/IPAddr.html#link_local-3F-source)
cc implementor `@little-dude`
(I can't find the original PR for `is_unqiue_local`)
r? libs-api
`@rustbot` label +T-libs-api +needs-fcp
This commit is contained in:
commit
2cf7908998
1 changed files with 4 additions and 6 deletions
|
@ -1594,16 +1594,15 @@ impl Ipv6Addr {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(ip)]
|
|
||||||
///
|
|
||||||
/// use std::net::Ipv6Addr;
|
/// use std::net::Ipv6Addr;
|
||||||
///
|
///
|
||||||
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unique_local(), false);
|
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unique_local(), false);
|
||||||
/// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 0).is_unique_local(), true);
|
/// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 0).is_unique_local(), true);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "ip", issue = "27709")]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[stable(feature = "ipv6_is_unique_local", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "ipv6_is_unique_local", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const fn is_unique_local(&self) -> bool {
|
pub const fn is_unique_local(&self) -> bool {
|
||||||
(self.segments()[0] & 0xfe00) == 0xfc00
|
(self.segments()[0] & 0xfe00) == 0xfc00
|
||||||
}
|
}
|
||||||
|
@ -1665,8 +1664,6 @@ impl Ipv6Addr {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(ip)]
|
|
||||||
///
|
|
||||||
/// use std::net::Ipv6Addr;
|
/// use std::net::Ipv6Addr;
|
||||||
///
|
///
|
||||||
/// // The loopback address (`::1`) does not actually have link-local scope.
|
/// // The loopback address (`::1`) does not actually have link-local scope.
|
||||||
|
@ -1680,9 +1677,10 @@ impl Ipv6Addr {
|
||||||
/// assert_eq!(Ipv6Addr::new(0xfe80, 0, 0, 1, 0, 0, 0, 0).is_unicast_link_local(), true);
|
/// assert_eq!(Ipv6Addr::new(0xfe80, 0, 0, 1, 0, 0, 0, 0).is_unicast_link_local(), true);
|
||||||
/// assert_eq!(Ipv6Addr::new(0xfe81, 0, 0, 0, 0, 0, 0, 0).is_unicast_link_local(), true);
|
/// assert_eq!(Ipv6Addr::new(0xfe81, 0, 0, 0, 0, 0, 0, 0).is_unicast_link_local(), true);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "ip", issue = "27709")]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[stable(feature = "ipv6_is_unique_local", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "ipv6_is_unique_local", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const fn is_unicast_link_local(&self) -> bool {
|
pub const fn is_unicast_link_local(&self) -> bool {
|
||||||
(self.segments()[0] & 0xffc0) == 0xfe80
|
(self.segments()[0] & 0xffc0) == 0xfe80
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue