Simplify impl_isqrt macro

We don't need multiple cases in the macro_rules!

Signed-off-by: Joe Richey <joerichey@google.com>
This commit is contained in:
Joe Richey 2020-09-07 20:19:44 -07:00
parent f96b2b2113
commit 260148e029
No known key found for this signature in database
GPG Key ID: 1DD6D05AA306C53F
1 changed files with 3 additions and 8 deletions

View File

@ -44,11 +44,8 @@ pub trait IntegerSquareRoot {
Self: Sized;
}
// This could be more optimized
macro_rules! impl_isqrt {
() => ();
($t:ty) => {impl_isqrt!($t,);};
($t:ty, $($e:tt)*) => {
($($t:ty)*) => { $(
impl IntegerSquareRoot for $t {
#[allow(unused_comparisons)]
fn integer_sqrt_checked(&self) -> Option<Self> {
@ -86,12 +83,10 @@ macro_rules! impl_isqrt {
Some(result)
}
}
impl_isqrt!($($e)*);
};
)* };
}
impl_isqrt!(usize, u128, u64, u32, u16, u8, isize, i128, i64, i32, i16, i8);
impl_isqrt!(usize u128 u64 u32 u16 u8 isize i128 i64 i32 i16 i8);
#[cfg(test)]
mod tests {