Skip to content

Commit

Permalink
Implement BitXor trait for U256 wrapper type to allow xor operations
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipLaurentiu committed Feb 6, 2025
1 parent 171b0c6 commit 7d3bf2e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions starknet-core/src/types/u256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ impl core::ops::RemAssign<Self> for U256 {
}
}

impl core::ops::BitXor for U256 {
type Output = Self;

fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0.bitxor(&rhs.0))
}
}

impl Display for U256 {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
if self.0.is_zero().into() {
Expand Down Expand Up @@ -387,4 +395,10 @@ mod tests {
fn test_u256_rem() {
assert_eq!(U256::from(100u32) % U256::from(3u32), U256::from(1u32));
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_u256_xor() {
assert_eq!(U256::from(100u32) ^ U256::from(3u32), U256::from(103u32));
}
}

0 comments on commit 7d3bf2e

Please sign in to comment.