Trait std::ops::ShlAssign

pub trait ShlAssign<Rhs = Self> {
    fn shl_assign(&mut self, rhs: Rhs);
}

The left shift assignment operator <<=.

Examples

An implementation of ShlAssign for a wrapper around usize.

use std::ops::ShlAssign;

#[derive(Debug, PartialEq)]
struct Scalar(usize);

impl ShlAssign<usize> for Scalar {
    fn shl_assign(&mut self, rhs: usize) {
        self.0 <<= rhs;
    }
}

let mut scalar = Scalar(4);
scalar <<= 2;
assert_eq!(scalar, Scalar(16));

Required methods

Performs the <<= operation.

Examples

let mut x: u8 = 5;
x <<= 1;
assert_eq!(x, 10);

let mut x: u8 = 1;
x <<= 1;
assert_eq!(x, 2);

Implementors

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/ops/trait.ShlAssign.html