Skip to content

std::bitwise

Protocols for the bitwise operators: &&&, |||, ^^^, prefix ~~~, <<< and >>>. Int implements all six; Byte implements the four that keep a value within 8 bits, and no shift.

Import with import std::bitwise.

interface BitwiseAnd<Rhs, Out>
    fn bitwise_and(lhs: self, rhs: Rhs) -> Out
end

Protocol for the &&& operator, bitwise and.

BitwiseAnd.bitwise_and(lhs, rhs) returns the result of lhs &&& rhs. The left-hand type is the implementor (self); the interface type parameters describe the right-hand operand and the output type, as Add’s do.

pub type Flags Int

impl BitwiseAnd<Flags, Flags> for Flags
    fn bitwise_and(lhs: Flags, rhs: Flags) -> Flags
        ...
    end
end
fn bitwise_and(lhs: self, rhs: Rhs) -> Out

interface BitwiseAnd

interface BitwiseOr<Rhs, Out>
    fn bitwise_or(lhs: self, rhs: Rhs) -> Out
end

Protocol for the ||| operator, bitwise or. See BitwiseAnd.

fn bitwise_or(lhs: self, rhs: Rhs) -> Out

interface BitwiseOr

interface BitwiseXor<Rhs, Out>
    fn bitwise_xor(lhs: self, rhs: Rhs) -> Out
end

Protocol for the ^^^ operator, bitwise exclusive or. See BitwiseAnd.

fn bitwise_xor(lhs: self, rhs: Rhs) -> Out

interface BitwiseXor

interface BitwiseNot<Out>
    fn bitwise_not(value: self) -> Out
end

Protocol for the prefix ~~~ operator, bitwise not. The operand is the implementor (self); the type parameter is the result type.

fn bitwise_not(value: self) -> Out

interface BitwiseNot

interface ShiftLeft<Rhs, Out>
    fn shift_left(lhs: self, rhs: Rhs) -> Out
end

Protocol for the <<< operator, shift left. See BitwiseAnd.

fn shift_left(lhs: self, rhs: Rhs) -> Out

interface ShiftLeft

interface ShiftRight<Rhs, Out>
    fn shift_right(lhs: self, rhs: Rhs) -> Out
end

Protocol for the >>> operator, arithmetic shift right. See BitwiseAnd.

fn shift_right(lhs: self, rhs: Rhs) -> Out

interface ShiftRight