Trait std::ops::ShrAssign1.8.0[][src]

pub trait ShrAssign<Rhs = Self> {
    fn shr_assign(&mut self, rhs: Rhs);
}
Expand description

右移赋值运算符 >>=

Examples

ShrAssign 的实现,用于围绕 usize 的包装。

use std::ops::ShrAssign;

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

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

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

Required methods

执行 >>= 操作。

Examples

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

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

Implementors