Trait in prelude::ops auto-imported

Shl

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

The left shift operator <<.

a << n on a type with a Shl instance calls shl(a, n). The shift count is always an int, whatever the type of a, and the result has the type of a. int and byte have builtin instances; shifting a byte keeps the low 8 bits.

Required methods#

NameDescription
shlReturns a shifted left by n bits.

Examples#

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

impl Shl for Flags {
    pub fn shl(Flags a, int n) -> Flags {
        return new Flags(a.bits << n);
    }
}

fn main() {
    let f = new Flags(1) << 3;
    assert!(f.bits == 8);
}

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