@@ -188,8 +188,6 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> {
188
188
}
189
189
}
190
190
191
- mod wrapping;
192
-
193
191
// All these modules are technically private and only exposed for coretests:
194
192
pub mod flt2dec;
195
193
pub mod dec2flt;
@@ -203,6 +201,8 @@ macro_rules! doc_comment {
203
201
} ;
204
202
}
205
203
204
+ mod wrapping;
205
+
206
206
// `Int` + `SignedInt` implemented for signed integers
207
207
macro_rules! int_impl {
208
208
( $SelfT: ty, $ActualT: ident, $UnsignedT: ty, $BITS: expr, $Min: expr, $Max: expr, $Feature: expr,
@@ -3423,6 +3423,29 @@ $EndFeature, "
3423
3423
}
3424
3424
}
3425
3425
3426
+ doc_comment! {
3427
+ concat!( "Returns the smallest power of two greater than or equal to `n`. If
3428
+ the next power of two is greater than the type's maximum value,
3429
+ the return value is wrapped to `0`.
3430
+
3431
+ # Examples
3432
+
3433
+ Basic usage:
3434
+
3435
+ ```
3436
+ #![feature(wrapping_int_impl)]
3437
+ " , $Feature, "
3438
+ assert_eq!(2" , stringify!( $SelfT) , ".wrapping_next_power_of_two(), 2);
3439
+ assert_eq!(3" , stringify!( $SelfT) , ".wrapping_next_power_of_two(), 4);
3440
+ assert_eq!(" , stringify!( $SelfT) , "::max_value().wrapping_next_power_of_two(), 0);" ,
3441
+ $EndFeature, "
3442
+ ```" ) ,
3443
+ #[ unstable( feature = "wrapping_int_impl" , issue = "32463" ) ]
3444
+ pub fn wrapping_next_power_of_two( self ) -> Self {
3445
+ self . one_less_than_next_power_of_two( ) . wrapping_add( 1 )
3446
+ }
3447
+ }
3448
+
3426
3449
/// Return the memory representation of this integer as a byte array.
3427
3450
///
3428
3451
/// The target platform’s native endianness is used.
0 commit comments