Skip to content

Commit

Permalink
implement partialeq for pylong and i128 and u128
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamTakeshi committed Jul 7, 2024
1 parent 6b6825b commit 652c196
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/types/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,38 @@ impl PartialEq<Bound<'_, PyLong>> for u64 {
}
}

/// Implement <Bound<'_, PyLong>> == i128 comparisons
impl PartialEq<i128> for Bound<'_, PyLong> {
#[inline]
fn eq(&self, other: &i128) -> bool {
self.value() == *other as c_long
}
}

/// Implement i128 == <Bound<'_, PyLong>> comparisons
impl PartialEq<Bound<'_, PyLong>> for i128 {
#[inline]
fn eq(&self, other: &Bound<'_, PyLong>) -> bool {
*self as c_long == other.value()
}
}

/// Implement <Bound<'_, PyLong>> == u128 comparisons
impl PartialEq<u128> for Bound<'_, PyLong> {
#[inline]
fn eq(&self, other: &u128) -> bool {
self.value() == *other as c_long
}
}

/// Implement u128 == <Bound<'_, PyLong>> comparisons
impl PartialEq<Bound<'_, PyLong>> for u128 {
#[inline]
fn eq(&self, other: &Bound<'_, PyLong>) -> bool {
*self as c_long == other.value()
}
}

/// Implement <Bound<'_, PyLong>> == isize comparisons
impl PartialEq<isize> for Bound<'_, PyLong> {
#[inline]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -261,12 +295,17 @@ 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);

assert_eq!(v_usize, obj);
assert_eq!(obj, v_usize);
});
}

}

0 comments on commit 652c196

Please sign in to comment.