traits: inline PrimInt methods

This commit is contained in:
Josh Stone 2016-08-10 22:21:00 -07:00
parent d9f08cb148
commit 7bc7ddfc87
1 changed files with 16 additions and 0 deletions

View File

@ -280,66 +280,82 @@ pub trait PrimInt
macro_rules! prim_int_impl { macro_rules! prim_int_impl {
($T:ty, $S:ty, $U:ty) => ( ($T:ty, $S:ty, $U:ty) => (
impl PrimInt for $T { impl PrimInt for $T {
#[inline]
fn count_ones(self) -> u32 { fn count_ones(self) -> u32 {
<$T>::count_ones(self) <$T>::count_ones(self)
} }
#[inline]
fn count_zeros(self) -> u32 { fn count_zeros(self) -> u32 {
<$T>::count_zeros(self) <$T>::count_zeros(self)
} }
#[inline]
fn leading_zeros(self) -> u32 { fn leading_zeros(self) -> u32 {
<$T>::leading_zeros(self) <$T>::leading_zeros(self)
} }
#[inline]
fn trailing_zeros(self) -> u32 { fn trailing_zeros(self) -> u32 {
<$T>::trailing_zeros(self) <$T>::trailing_zeros(self)
} }
#[inline]
fn rotate_left(self, n: u32) -> Self { fn rotate_left(self, n: u32) -> Self {
<$T>::rotate_left(self, n) <$T>::rotate_left(self, n)
} }
#[inline]
fn rotate_right(self, n: u32) -> Self { fn rotate_right(self, n: u32) -> Self {
<$T>::rotate_right(self, n) <$T>::rotate_right(self, n)
} }
#[inline]
fn signed_shl(self, n: u32) -> Self { fn signed_shl(self, n: u32) -> Self {
((self as $S) << n) as $T ((self as $S) << n) as $T
} }
#[inline]
fn signed_shr(self, n: u32) -> Self { fn signed_shr(self, n: u32) -> Self {
((self as $S) >> n) as $T ((self as $S) >> n) as $T
} }
#[inline]
fn unsigned_shl(self, n: u32) -> Self { fn unsigned_shl(self, n: u32) -> Self {
((self as $U) << n) as $T ((self as $U) << n) as $T
} }
#[inline]
fn unsigned_shr(self, n: u32) -> Self { fn unsigned_shr(self, n: u32) -> Self {
((self as $U) >> n) as $T ((self as $U) >> n) as $T
} }
#[inline]
fn swap_bytes(self) -> Self { fn swap_bytes(self) -> Self {
<$T>::swap_bytes(self) <$T>::swap_bytes(self)
} }
#[inline]
fn from_be(x: Self) -> Self { fn from_be(x: Self) -> Self {
<$T>::from_be(x) <$T>::from_be(x)
} }
#[inline]
fn from_le(x: Self) -> Self { fn from_le(x: Self) -> Self {
<$T>::from_le(x) <$T>::from_le(x)
} }
#[inline]
fn to_be(self) -> Self { fn to_be(self) -> Self {
<$T>::to_be(self) <$T>::to_be(self)
} }
#[inline]
fn to_le(self) -> Self { fn to_le(self) -> Self {
<$T>::to_le(self) <$T>::to_le(self)
} }
#[inline]
fn pow(self, exp: u32) -> Self { fn pow(self, exp: u32) -> Self {
<$T>::pow(self, exp) <$T>::pow(self, exp)
} }