Skip to content

Commit f3edf94

Browse files
committed
Implement operations for Wrapping<T> where Rhs = T
1 parent 0e517d3 commit f3edf94

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

library/core/src/num/wrapping.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,18 @@ macro_rules! wrapping_impl {
221221
forward_ref_binop! { impl Add, add for Wrapping<$t>, Wrapping<$t>,
222222
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
223223

224+
225+
#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
226+
impl Add<$t> for Wrapping<$t> {
227+
type Output = Wrapping<$t>;
228+
229+
#[inline]
230+
fn add(self, other: $t) -> Wrapping<$t> {
231+
Wrapping(self.0.wrapping_add(other))
232+
}
233+
}
234+
forward_ref_binop! { impl Add, add for Wrapping<$t>, $t }
235+
224236
#[stable(feature = "op_assign_traits", since = "1.8.0")]
225237
impl AddAssign for Wrapping<$t> {
226238
#[inline]
@@ -251,6 +263,17 @@ macro_rules! wrapping_impl {
251263
forward_ref_binop! { impl Sub, sub for Wrapping<$t>, Wrapping<$t>,
252264
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
253265

266+
#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
267+
impl Sub<$t> for Wrapping<$t> {
268+
type Output = Wrapping<$t>;
269+
270+
#[inline]
271+
fn sub(self, other: $t) -> Wrapping<$t> {
272+
Wrapping(self.0.wrapping_sub(other))
273+
}
274+
}
275+
forward_ref_binop! { impl Sub, sub for Wrapping<$t>, $t }
276+
254277
#[stable(feature = "op_assign_traits", since = "1.8.0")]
255278
impl SubAssign for Wrapping<$t> {
256279
#[inline]
@@ -281,6 +304,17 @@ macro_rules! wrapping_impl {
281304
forward_ref_binop! { impl Mul, mul for Wrapping<$t>, Wrapping<$t>,
282305
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
283306

307+
#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
308+
impl Mul<$t> for Wrapping<$t> {
309+
type Output = Wrapping<$t>;
310+
311+
#[inline]
312+
fn mul(self, other: $t) -> Wrapping<$t> {
313+
Wrapping(self.0.wrapping_mul(other))
314+
}
315+
}
316+
forward_ref_binop! { impl Mul, mul for Wrapping<$t>, $t }
317+
284318
#[stable(feature = "op_assign_traits", since = "1.8.0")]
285319
impl MulAssign for Wrapping<$t> {
286320
#[inline]
@@ -311,6 +345,17 @@ macro_rules! wrapping_impl {
311345
forward_ref_binop! { impl Div, div for Wrapping<$t>, Wrapping<$t>,
312346
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
313347

348+
#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
349+
impl Div<$t> for Wrapping<$t> {
350+
type Output = Wrapping<$t>;
351+
352+
#[inline]
353+
fn div(self, other: $t) -> Wrapping<$t> {
354+
Wrapping(self.0.wrapping_div(other))
355+
}
356+
}
357+
forward_ref_binop! { impl Div, div for Wrapping<$t>, $t }
358+
314359
#[stable(feature = "op_assign_traits", since = "1.8.0")]
315360
impl DivAssign for Wrapping<$t> {
316361
#[inline]
@@ -341,6 +386,17 @@ macro_rules! wrapping_impl {
341386
forward_ref_binop! { impl Rem, rem for Wrapping<$t>, Wrapping<$t>,
342387
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
343388

389+
#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
390+
impl Rem<$t> for Wrapping<$t> {
391+
type Output = Wrapping<$t>;
392+
393+
#[inline]
394+
fn rem(self, other: $t) -> Wrapping<$t> {
395+
Wrapping(self.0.wrapping_rem(other))
396+
}
397+
}
398+
forward_ref_binop! { impl Rem, rem for Wrapping<$t>, $t }
399+
344400
#[stable(feature = "op_assign_traits", since = "1.8.0")]
345401
impl RemAssign for Wrapping<$t> {
346402
#[inline]
@@ -383,6 +439,17 @@ macro_rules! wrapping_impl {
383439
forward_ref_binop! { impl BitXor, bitxor for Wrapping<$t>, Wrapping<$t>,
384440
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
385441

442+
#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
443+
impl BitXor<$t> for Wrapping<$t> {
444+
type Output = Wrapping<$t>;
445+
446+
#[inline]
447+
fn bitxor(self, other: $t) -> Wrapping<$t> {
448+
Wrapping(self.0 ^ other)
449+
}
450+
}
451+
forward_ref_binop! { impl BitXor, bitxor for Wrapping<$t>, $t }
452+
386453
#[stable(feature = "op_assign_traits", since = "1.8.0")]
387454
impl BitXorAssign for Wrapping<$t> {
388455
#[inline]
@@ -413,6 +480,17 @@ macro_rules! wrapping_impl {
413480
forward_ref_binop! { impl BitOr, bitor for Wrapping<$t>, Wrapping<$t>,
414481
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
415482

483+
#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
484+
impl BitOr<$t> for Wrapping<$t> {
485+
type Output = Wrapping<$t>;
486+
487+
#[inline]
488+
fn bitor(self, other: $t) -> Wrapping<$t> {
489+
Wrapping(self.0 | other)
490+
}
491+
}
492+
forward_ref_binop! { impl BitOr, bitor for Wrapping<$t>, $t }
493+
416494
#[stable(feature = "op_assign_traits", since = "1.8.0")]
417495
impl BitOrAssign for Wrapping<$t> {
418496
#[inline]
@@ -443,6 +521,17 @@ macro_rules! wrapping_impl {
443521
forward_ref_binop! { impl BitAnd, bitand for Wrapping<$t>, Wrapping<$t>,
444522
#[stable(feature = "wrapping_ref", since = "1.14.0")] }
445523

524+
#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
525+
impl BitAnd<$t> for Wrapping<$t> {
526+
type Output = Wrapping<$t>;
527+
528+
#[inline]
529+
fn bitand(self, other: $t) -> Wrapping<$t> {
530+
Wrapping(self.0 & other)
531+
}
532+
}
533+
forward_ref_binop! { impl BitAnd, bitand for Wrapping<$t>, $t }
534+
446535
#[stable(feature = "op_assign_traits", since = "1.8.0")]
447536
impl BitAndAssign for Wrapping<$t> {
448537
#[inline]

0 commit comments

Comments
 (0)