about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-05-13 15:54:13 +0200
committerGitHub <noreply@github.com>2021-05-13 15:54:13 +0200
commit16c825485fa51193cedc3dd9394c0a2f31016c42 (patch)
treecb70a7f32238c6747ada47228f0af74f8a674769
parent5aa40dda855d7c0562655903e1daa018d78297e7 (diff)
parenta381e291174676fba8d85c9354b4da723111ff11 (diff)
downloadrust-16c825485fa51193cedc3dd9394c0a2f31016c42.tar.gz
rust-16c825485fa51193cedc3dd9394c0a2f31016c42.zip
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.
-rw-r--r--library/core/src/num/wrapping.rs15
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