pub trait bitwise {
// Provided methods
fn __band(&self, other: any) -> any { ... }
fn __bor(&self, other: any) -> any { ... }
fn __bxor(&self, other: any) -> any { ... }
fn __bnot(&self) -> any { ... }
fn __shl(&self, other: any) -> any { ... }
fn __shr(&self, other: any) -> any { ... }
}Expand description
Metamethods controlling the bitwise operators.
These events fire when a bitwise operator is applied to an operand that is neither an integer nor a value convertible to an integer.
Provided Methods§
Sourcefn __band(&self, other: any) -> any
fn __band(&self, other: any) -> any
The bitwise AND (&) operation.
§Examples
local mt = { __band = function(a, b) return a.bits & b.bits end }
local a = setmetatable({ bits = 0x0F }, mt)
local b = setmetatable({ bits = 0x03 }, mt)
print(a & b) --> 3Sourcefn __bor(&self, other: any) -> any
fn __bor(&self, other: any) -> any
The bitwise OR (|) operation.
§Examples
mt.__bor = function(a, b) return a.bits | b.bits end
print(a | b) --> 15Sourcefn __bxor(&self, other: any) -> any
fn __bxor(&self, other: any) -> any
The bitwise exclusive OR (~) operation.
§Examples
mt.__bxor = function(a, b) return a.bits ~ b.bits end
print(a ~ b) --> 12Sourcefn __bnot(&self) -> any
fn __bnot(&self) -> any
The bitwise NOT (unary ~) operation.
§Examples
mt.__bnot = function(v) return ~v.bits & 0xFF end
print(~a) --> 240Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".