diff options
| author | Trevor Spiteri <tspiteri@ieee.org> | 2021-05-11 13:36:43 +0200 |
|---|---|---|
| committer | Trevor Spiteri <tspiteri@ieee.org> | 2021-05-11 13:36:43 +0200 |
| commit | a381e291174676fba8d85c9354b4da723111ff11 (patch) | |
| tree | b5e5e057fa048fe893197c0b88305cba409a03ed | |
| parent | 382f748f23979e37e3e012b090e5a0313463f182 (diff) | |
| download | rust-a381e291174676fba8d85c9354b4da723111ff11.tar.gz rust-a381e291174676fba8d85c9354b4da723111ff11.zip | |
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.
| -rw-r--r-- | library/core/src/num/wrapping.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/library/core/src/num/wrapping.rs b/library/core/src/num/wrapping.rs index f1b9dabe7d6..be6d70320d4 100644 --- a/library/core/src/num/wrapping.rs +++ b/library/core/src/num/wrapping.rs @@ -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 |
