Simplify PortalOrd macro
timw4mail/rusty-numbers/pipeline/head There was a failure building this commit Details

This commit is contained in:
Timothy Warren 2020-05-05 18:49:19 -04:00
parent e54485f12b
commit cf262073dd
1 changed files with 21 additions and 28 deletions

View File

@ -489,34 +489,32 @@ macro_rules! impl_from_larger {
}
macro_rules! impl_ord_literal {
($(($($prim: ty),+), $base: ty), *) => {
($($prim: ty),+) => {
$(
$(
impl PartialEq<$prim> for BigInt {
fn eq(&self, other: &$prim) -> bool {
self == &BigInt::from(*other)
}
impl PartialEq<$prim> for BigInt {
fn eq(&self, other: &$prim) -> bool {
self == &BigInt::from(*other)
}
}
impl PartialEq<BigInt> for $prim {
fn eq(&self, other: &BigInt) -> bool {
&BigInt::from(*self) == other
}
impl PartialEq<BigInt> for $prim {
fn eq(&self, other: &BigInt) -> bool {
&BigInt::from(*self) == other
}
}
impl PartialOrd<$prim> for BigInt {
fn partial_cmp(&self, other: &$prim) -> Option<Ordering> {
self.partial_cmp(&BigInt::from(*other))
}
impl PartialOrd<$prim> for BigInt {
fn partial_cmp(&self, other: &$prim) -> Option<Ordering> {
self.partial_cmp(&BigInt::from(*other))
}
}
impl PartialOrd<BigInt> for $prim {
fn partial_cmp(&self, other: &BigInt) -> Option<Ordering> {
(&BigInt::from(*self)).partial_cmp(other)
}
impl PartialOrd<BigInt> for $prim {
fn partial_cmp(&self, other: &BigInt) -> Option<Ordering> {
(&BigInt::from(*self)).partial_cmp(other)
}
)+
)*
}
)+
};
}
@ -524,19 +522,14 @@ macro_rules! impl_ord_literal {
impl_from_larger!((i64, u64), (i128, u128));
#[cfg(target_pointer_width = "32")]
impl_from_smaller!((i8, u8), (i16, u16), (i32, u32));
#[cfg(target_pointer_width = "32")]
impl_ord_literal!((i8,u8,i16,u16,i32,u32,i64,u64), u32);
#[cfg(target_pointer_width = "32")]
static BITS: usize = 32;
#[cfg(target_pointer_width = "64")]
impl_from_larger!((i128, u128));
#[cfg(target_pointer_width = "64")]
impl_from_smaller!((i8, u8), (i16, u16), (i32, u32), (i64, u64));
#[cfg(target_pointer_width = "64")]
impl_ord_literal!((i8,u8,i16,u16,i32,u32,i64,u64), u32);
#[cfg(target_pointer_width = "64")]
static BITS: usize = 64;
// Implement PartialEq and PartialOrd to compare against BigInt values
impl_ord_literal!(i8,u8,i16,u16,i32,u32,i64,u64,i128,u128);
#[cfg(test)]
#[cfg_attr(tarpaulin, skip)]