From 555dab7d332370822b97a2e13ff02f46e5404376 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Sun, 3 Sep 2017 09:56:29 +0200 Subject: [PATCH] Implement ShrAssign and ShlAssign for BigUint --- bigint/src/biguint.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bigint/src/biguint.rs b/bigint/src/biguint.rs index 692c5d7..66eff38 100644 --- a/bigint/src/biguint.rs +++ b/bigint/src/biguint.rs @@ -1,7 +1,9 @@ use std::borrow::Cow; use std::default::Default; use std::iter::repeat; -use std::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Rem, Shl, Shr, Sub, AddAssign, SubAssign, MulAssign, DivAssign, RemAssign, BitAndAssign, BitOrAssign, BitXorAssign}; +use std::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Rem, Shl, Shr, Sub, + AddAssign, BitAndAssign, BitOrAssign, BitXorAssign, DivAssign, + MulAssign, RemAssign, ShlAssign, ShrAssign, SubAssign}; use std::str::{self, FromStr}; use std::fmt; use std::cmp; @@ -346,7 +348,6 @@ impl Shl for BigUint { biguint_shl(Cow::Owned(self), rhs) } } - impl<'a> Shl for &'a BigUint { type Output = BigUint; @@ -356,6 +357,13 @@ impl<'a> Shl for &'a BigUint { } } +impl ShlAssign for BigUint { + #[inline] + fn shl_assign(&mut self, rhs: usize) { + *self = biguint_shl(Cow::Borrowed(&*self), rhs); + } +} + impl Shr for BigUint { type Output = BigUint; @@ -364,7 +372,6 @@ impl Shr for BigUint { biguint_shr(Cow::Owned(self), rhs) } } - impl<'a> Shr for &'a BigUint { type Output = BigUint; @@ -374,6 +381,13 @@ impl<'a> Shr for &'a BigUint { } } +impl ShrAssign for BigUint { + #[inline] + fn shr_assign(&mut self, rhs: usize) { + *self = biguint_shr(Cow::Borrowed(&*self), rhs); + } +} + impl Zero for BigUint { #[inline] fn zero() -> BigUint {