Revert impl for Checked and Saturating

This commit is contained in:
Yoan Lecoq 2017-04-30 08:29:21 +02:00
parent 760604361d
commit 81aa6dbe48
2 changed files with 0 additions and 40 deletions

View File

@ -1,5 +1,4 @@
use std::ops::{Add, Sub, Mul, Div};
use std::num::Wrapping;
/// Performs addition that returns `None` instead of wrapping around on
/// overflow.
@ -91,33 +90,3 @@ checked_impl!(CheckedDiv, checked_div, i32);
checked_impl!(CheckedDiv, checked_div, i64);
checked_impl!(CheckedDiv, checked_div, isize);
// Was skeptical at first, since checked ops somewhat defeat the point of
// Wrapping<T>, but there are more pros than cons IMO :
// - These are methods, so users still have to be explicit about their intent;
// - Wrapping<T> could be used for to enforce wrapping semantics _most of the time_,
// and only have a handful of places where they want to perform checked ops;
// - This allows Wrapping<T> to implement PrimInt.
impl<T: CheckedAdd> CheckedAdd for Wrapping<T> where Wrapping<T>: Add<Output = Wrapping<T>>{
#[inline]
fn checked_add(&self, v: &Self) -> Option<Self> {
self.0.checked_add(&v.0).map(Wrapping)
}
}
impl<T: CheckedSub> CheckedSub for Wrapping<T> where Wrapping<T>: Sub<Output = Wrapping<T>> {
#[inline]
fn checked_sub(&self, v: &Self) -> Option<Self> {
self.0.checked_sub(&v.0).map(Wrapping)
}
}
impl<T: CheckedMul> CheckedMul for Wrapping<T> where Wrapping<T>: Mul<Output = Wrapping<T>>{
#[inline]
fn checked_mul(&self, v: &Self) -> Option<Self> {
self.0.checked_mul(&v.0).map(Wrapping)
}
}
impl<T: CheckedDiv> CheckedDiv for Wrapping<T> where Wrapping<T>: Div<Output = Wrapping<T>> {
#[inline]
fn checked_div(&self, v: &Self) -> Option<Self> {
self.0.checked_div(&v.0).map(Wrapping)
}
}

View File

@ -1,5 +1,3 @@
use std::num::Wrapping;
/// Saturating math operations
pub trait Saturating {
/// Saturating addition operator.
@ -28,10 +26,3 @@ macro_rules! saturating_impl {
}
saturating_impl!(Saturating for isize usize i8 u8 i16 u16 i32 u32 i64 u64);
impl<T: Saturating> Saturating for Wrapping<T> {
#[inline]
fn saturating_add(self, v: Self) -> Self { Wrapping(self.0.saturating_add(v.0)) }
#[inline]
fn saturating_sub(self, v: Self) -> Self { Wrapping(self.0.saturating_sub(v.0)) }
}