Skip to content

Commit

Permalink
add BITS associated constant to core::num::Wrapping
Browse files Browse the repository at this point in the history
This keeps `Wrapping` synchronized with the primitives it wraps as for
the rust-lang#32463 `wrapping_int_impl` feature.
  • Loading branch information
tspiteri committed May 11, 2021
1 parent 382f748 commit a381e29
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions library/core/src/num/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,21 @@ macro_rules! wrapping_int_impl {
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const MAX: Self = Self(<$t>::MAX);

/// Returns the size of this integer type in bits.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(wrapping_int_impl)]
/// use std::num::Wrapping;
///
#[doc = concat!("assert_eq!(<Wrapping<", stringify!($t), ">>::BITS, ", stringify!($t), "::BITS);")]
/// ```
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const BITS: u32 = <$t>::BITS;

/// Returns the number of ones in the binary representation of `self`.
///
/// # Examples
Expand Down

0 comments on commit a381e29

Please sign in to comment.