Trait core::ops::BitwiseAnd
pub trait BitwiseAnd {
/// Bitwise AND two values of the same type.
///
/// # Arguments
///
/// * `other`: [Self] - The value of the same type.
///
/// # Returns
///
/// * [Self] - The result of the bitwise AND of the two values.
///
/// # Examples
///
/// ```sway
/// struct MyStruct {
/// val: u64,
/// }
///
/// impl BitwiseAnd for MyStruct {
/// fn binary_and(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 == 10);
/// }
/// ```
fn binary_and(self, other: Self) -> Self;
}
Expand description
Trait to bitwise AND two values of the same type.
Required Methods
fn binary_and(self, other: Self) -> Self
fn binary_and(self, other: Self) -> Self
Bitwise AND two values of the same type.
Arguments
other
: [Self] - The value of the same type.
Returns
- [Self] - The result of the bitwise AND of the two values.
Examples
struct MyStruct {
val: u64,
}
impl BitwiseAnd for MyStruct {
fn binary_and(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 == 10);
}