diff --git a/src/types/num.rs b/src/types/num.rs index 166a9850494..b38e19279b0 100644 --- a/src/types/num.rs +++ b/src/types/num.rs @@ -176,6 +176,38 @@ impl PartialEq> for u64 { } } +/// Implement > == i128 comparisons +impl PartialEq for Bound<'_, PyLong> { + #[inline] + fn eq(&self, other: &i128) -> bool { + self.value() == *other as c_long + } +} + +/// Implement i128 == > comparisons +impl PartialEq> for i128 { + #[inline] + fn eq(&self, other: &Bound<'_, PyLong>) -> bool { + *self as c_long == other.value() + } +} + +/// Implement > == u128 comparisons +impl PartialEq for Bound<'_, PyLong> { + #[inline] + fn eq(&self, other: &u128) -> bool { + self.value() == *other as c_long + } +} + +/// Implement u128 == > comparisons +impl PartialEq> for u128 { + #[inline] + fn eq(&self, other: &Bound<'_, PyLong>) -> bool { + *self as c_long == other.value() + } +} + /// Implement > == isize comparisons impl PartialEq for Bound<'_, PyLong> { #[inline] @@ -234,6 +266,8 @@ mod tests { let v_u32 = 123u32; let v_i64 = 123i64; let v_u64 = 123u64; + let v_i128 = 123i128; + let v_u128 = 123u128; let v_isize = 123isize; let v_usize = 123usize; let obj = PyLong::new_bound_from_c_long(py, 123); @@ -261,6 +295,12 @@ mod tests { assert_eq!(v_u64, obj); assert_eq!(obj, v_u64); + assert_eq!(v_i128, obj); + assert_eq!(obj, v_i128); + + assert_eq!(v_u128, obj); + assert_eq!(obj, v_u128); + assert_eq!(v_isize, obj); assert_eq!(obj, v_isize); @@ -268,5 +308,4 @@ mod tests { assert_eq!(obj, v_usize); }); } - }