Add missing Wrapping methods, use doc_comment!

This commit is contained in:
Clar Charr
2018-03-26 16:46:04 -04:00
parent b183bd0ad4
commit a00e68ddc6
2 changed files with 486 additions and 199 deletions

View File

@@ -188,8 +188,6 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> {
}
}
mod wrapping;
// All these modules are technically private and only exposed for coretests:
pub mod flt2dec;
pub mod dec2flt;
@@ -203,6 +201,8 @@ macro_rules! doc_comment {
};
}
mod wrapping;
// `Int` + `SignedInt` implemented for signed integers
macro_rules! int_impl {
($SelfT:ty, $ActualT:ident, $UnsignedT:ty, $BITS:expr, $Min:expr, $Max:expr, $Feature:expr,
@@ -3423,6 +3423,29 @@ $EndFeature, "
}
}
doc_comment! {
concat!("Returns the smallest power of two greater than or equal to `n`. If
the next power of two is greater than the type's maximum value,
the return value is wrapped to `0`.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
", $Feature, "
assert_eq!(2", stringify!($SelfT), ".wrapping_next_power_of_two(), 2);
assert_eq!(3", stringify!($SelfT), ".wrapping_next_power_of_two(), 4);
assert_eq!(", stringify!($SelfT), "::max_value().wrapping_next_power_of_two(), 0);",
$EndFeature, "
```"),
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn wrapping_next_power_of_two(self) -> Self {
self.one_less_than_next_power_of_two().wrapping_add(1)
}
}
/// Return the memory representation of this integer as a byte array.
///
/// The target platforms native endianness is used.