Skip to content

Commit 16c8254

Browse files
Rollup merge of #85177 - tspiteri:wrapping-bits, r=joshtriplett
add BITS associated constant to core::num::Wrapping This keeps `Wrapping` synchronized with the primitives it wraps as for the #32463 `wrapping_int_impl` feature.
2 parents 5aa40dd + a381e29 commit 16c8254

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

library/core/src/num/wrapping.rs

+15
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,21 @@ macro_rules! wrapping_int_impl {
433433
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
434434
pub const MAX: Self = Self(<$t>::MAX);
435435

436+
/// Returns the size of this integer type in bits.
437+
///
438+
/// # Examples
439+
///
440+
/// Basic usage:
441+
///
442+
/// ```
443+
/// #![feature(wrapping_int_impl)]
444+
/// use std::num::Wrapping;
445+
///
446+
#[doc = concat!("assert_eq!(<Wrapping<", stringify!($t), ">>::BITS, ", stringify!($t), "::BITS);")]
447+
/// ```
448+
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
449+
pub const BITS: u32 = <$t>::BITS;
450+
436451
/// Returns the number of ones in the binary representation of `self`.
437452
///
438453
/// # Examples

0 commit comments

Comments
 (0)