Trait in prelude::ops auto-imported

BitNot

trait BitNot<T>
Source: compiler/src/builtin_docs/prelude/ops.hy

The bitwise NOT operator ~x.

~x on a type with a BitNot instance calls bitnot(x). Only int has a builtin instance (~x is -x - 1); byte does not.

Required methods#

NameDescription
bitnotReturns a with every bit flipped.

Examples#

use tests::assert;
class Flags {
    pub bits: int,
}

impl BitNot for Flags {
    pub fn bitnot(Flags a) -> Flags {
        return new Flags(~a.bits);
    }
}

fn main() {
    let f = ~new Flags(0);
    assert!(f.bits == -1);
}

See also#

  • int
  • byte
  • Add: The addition operator +.
  • Sub: The subtraction operator -.
  • Mul: The multiplication operator *.
  • Div: The division operator /.
  • Neg: The unary negation operator -x.
  • Rem: The remainder operator %.
↑ ↓ navigate ↵ open