Trait rug::ops::ShrFrom

source ·
pub trait ShrFrom<Lhs = Self> {
    fn shr_from(&mut self, lhs: Lhs);
}
Expand description

Compound right shift and assignment to the rhs operand.

rhs.shr_from(lhs) has the same effect as rhs = lhs >> rhs.

Examples

use core::mem;
use rug::ops::ShrFrom;
use rug::Integer;
struct I(Integer);
impl ShrFrom for I {
    fn shr_from(&mut self, mut lhs: I) {
        let rhs = self.0.to_i32().expect("overflow");
        mem::swap(self, &mut lhs);
        self.0 >>= rhs;
    }
}
let mut i = I(Integer::from(4));
i.shr_from(I(Integer::from(0xf000)));
let expected = Integer::from(0xf000) >> 4;
assert_eq!(i.0, expected);

Required Methods

Peforms the right shift.

Examples
use rug::ops::ShrFrom;
let mut rhs = 4;
rhs.shr_from(0x00f0);
// rhs = 0x00f0 >> 4
assert_eq!(rhs, 0x000f);

Implementations on Foreign Types

Implementors