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

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

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@
#![feature(duration_consts_float)]
#![feature(internal_impls_macro)]
#![feature(ip)]
#![feature(ip_bits)]
#![feature(is_ascii_octdigit)]
#![feature(isqrt)]
#![feature(link_cfg)]
Expand Down
28 changes: 10 additions & 18 deletions library/core/src/net/ip_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,11 @@ impl Ipv4Addr {
/// # Examples
///
/// ```
/// #![feature(ip_bits)]
/// use std::net::Ipv4Addr;
///
/// assert_eq!(Ipv4Addr::BITS, 32);
/// ```
#[unstable(feature = "ip_bits", issue = "113744")]
#[stable(feature = "ip_bits", since = "CURRENT_RUSTC_VERSION")]
pub const BITS: u32 = 32;

/// Converts an IPv4 address into a `u32` representation using native byte order.
Expand All @@ -479,24 +478,22 @@ impl Ipv4Addr {
/// # Examples
///
/// ```
/// #![feature(ip_bits)]
/// use std::net::Ipv4Addr;
///
/// let addr = Ipv4Addr::new(0x12, 0x34, 0x56, 0x78);
/// assert_eq!(0x12345678, addr.to_bits());
/// ```
///
/// ```
/// #![feature(ip_bits)]
/// use std::net::Ipv4Addr;
///
/// let addr = Ipv4Addr::new(0x12, 0x34, 0x56, 0x78);
/// let addr_bits = addr.to_bits() & 0xffffff00;
/// assert_eq!(Ipv4Addr::new(0x12, 0x34, 0x56, 0x00), Ipv4Addr::from_bits(addr_bits));
///
/// ```
#[rustc_const_unstable(feature = "ip_bits", issue = "113744")]
#[unstable(feature = "ip_bits", issue = "113744")]
#[rustc_const_stable(feature = "ip_bits", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "ip_bits", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
#[inline]
pub const fn to_bits(self) -> u32 {
Expand All @@ -510,14 +507,13 @@ impl Ipv4Addr {
/// # Examples
///
/// ```
/// #![feature(ip_bits)]
/// use std::net::Ipv4Addr;
///
/// let addr = Ipv4Addr::from(0x12345678);
/// assert_eq!(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78), addr);
/// ```
#[rustc_const_unstable(feature = "ip_bits", issue = "113744")]
#[unstable(feature = "ip_bits", issue = "113744")]
#[rustc_const_stable(feature = "ip_bits", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "ip_bits", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
#[inline]
pub const fn from_bits(bits: u32) -> Ipv4Addr {
Expand Down Expand Up @@ -1238,12 +1234,11 @@ impl Ipv6Addr {
/// # Examples
///
/// ```
/// #![feature(ip_bits)]
/// use std::net::Ipv6Addr;
///
/// assert_eq!(Ipv6Addr::BITS, 128);
/// ```
#[unstable(feature = "ip_bits", issue = "113744")]
#[stable(feature = "ip_bits", since = "CURRENT_RUSTC_VERSION")]
pub const BITS: u32 = 128;

/// Converts an IPv6 address into a `u128` representation using native byte order.
Expand All @@ -1257,7 +1252,6 @@ impl Ipv6Addr {
/// # Examples
///
/// ```
/// #![feature(ip_bits)]
/// use std::net::Ipv6Addr;
///
/// let addr = Ipv6Addr::new(
Expand All @@ -1268,7 +1262,6 @@ impl Ipv6Addr {
/// ```
///
/// ```
/// #![feature(ip_bits)]
/// use std::net::Ipv6Addr;
///
/// let addr = Ipv6Addr::new(
Expand All @@ -1284,8 +1277,8 @@ impl Ipv6Addr {
/// Ipv6Addr::from_bits(addr_bits));
///
/// ```
#[rustc_const_unstable(feature = "ip_bits", issue = "113744")]
#[unstable(feature = "ip_bits", issue = "113744")]
#[rustc_const_stable(feature = "ip_bits", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "ip_bits", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
#[inline]
pub const fn to_bits(self) -> u128 {
Expand All @@ -1299,7 +1292,6 @@ impl Ipv6Addr {
/// # Examples
///
/// ```
/// #![feature(ip_bits)]
/// use std::net::Ipv6Addr;
///
/// let addr = Ipv6Addr::from(0x102030405060708090A0B0C0D0E0F00D_u128);
Expand All @@ -1310,8 +1302,8 @@ impl Ipv6Addr {
/// ),
/// addr);
/// ```
#[rustc_const_unstable(feature = "ip_bits", issue = "113744")]
#[unstable(feature = "ip_bits", issue = "113744")]
#[rustc_const_stable(feature = "ip_bits", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "ip_bits", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
#[inline]
pub const fn from_bits(bits: u128) -> Ipv6Addr {
Expand Down
Loading