pub trait BitwiseOr {
    /// Bitwise OR two values of the same type.
    ///
    /// # Arguments
    ///
    /// * `other`: [Self] - The value of the same type.
    ///
    /// # Returns
    ///
    /// * [Self] - The result of the bitwise OR of the two values.
    ///
    /// # Examples
    ///
    /// ```sway
    /// struct MyStruct {
    ///     val: u64,
    /// }
    ///
    /// impl BitwiseOr for MyStruct {
    ///     fn binary_or(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 == 11);
    /// }
    /// ```
    fn binary_or(self, other: Self) -> Self;
}
Expand description

Trait to bitwise OR two values of the same type.

Required Methods

Bitwise OR two values of the same type.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [Self] - The result of the bitwise OR of the two values.

Examples

struct MyStruct {
    val: u64,
}

impl BitwiseOr for MyStruct {
    fn binary_or(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 == 11);
}