Trait core::ops::BitwiseXor
pub trait BitwiseXor {
/// Bitwise XOR two values of the same type.
///
/// # Arguments
///
/// * `other`: [Self] - The value of the same type.
///
/// # Returns
///
/// * [Self] - The result of the bitwise XOR of the two values.
///
/// # Examples
///
/// ```sway
/// struct MyStruct {
/// val: u64,
/// }
///
/// impl BitwiseXOr for MyStruct {
/// fn binary_xor(self, other: Self) -> Self {
/// let val = self.val ^ other.val;
/// Self {
/// val
/// }
/// }
/// }
///
/// fn foo() {
/// let struct1 = MyStruct { val: 10 };
/// let struct2 = MyStruct { val: 11 };
/// let result_struct = struct1 ^ struct2;
/// assert(result_struct.val == 1);
/// }
/// ```
fn binary_xor(self, other: Self) -> Self;
}
Expand description
Trait to bitwise XOR two values of the same type.
Required Methods
fn binary_xor(self, other: Self) -> Self
fn binary_xor(self, other: Self) -> Self
Bitwise XOR two values of the same type.
Arguments
other
: [Self] - The value of the same type.
Returns
- [Self] - The result of the bitwise XOR of the two values.
Examples
struct MyStruct {
val: u64,
}
impl BitwiseXOr for MyStruct {
fn binary_xor(self, other: Self) -> Self {
let val = self.val ^ other.val;
Self {
val
}
}
}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 11 };
let result_struct = struct1 ^ struct2;
assert(result_struct.val == 1);
}