Trait core::ops::Not

pub trait Not {
    /// Inverts the value of the type.
    ///
    /// # Returns
    ///
    /// * [Self] - The result of the inverse.
    ///
    /// # Examples
    ///
    /// ```sway
    /// struct MyStruct {
    ///     val: bool,
    /// }
    ///
    /// impl Not for MyStruct {
    ///     fn not(self) -> Self {
    ///         Self {
    ///             val: !self.val,
    ///         }
    ///     }
    /// }
    ///
    /// fn foo() {
    ///     let struct = MyStruct { val: true };
    ///     let result_struct = !struct;
    ///     assert(!result_struct.val);
    /// }
    /// ```
    fn not(self) -> Self;
}
Expand description

Trait to invert a type.

Required Methods

Inverts the value of the type.

Returns

  • [Self] - The result of the inverse.

Examples

struct MyStruct {
    val: bool,
}

impl Not for MyStruct {
    fn not(self) -> Self {
        Self {
            val: !self.val,
        }
    }
}

fn foo() {
    let struct = MyStruct { val: true };
    let result_struct = !struct;
    assert(!result_struct.val);
}