From 81aa6dbe486d06b58e136bf3e15904e360072c2b Mon Sep 17 00:00:00 2001 From: Yoan Lecoq Date: Sun, 30 Apr 2017 08:29:21 +0200 Subject: [PATCH] Revert impl for Checked and Saturating --- traits/src/ops/checked.rs | 31 ------------------------------- traits/src/ops/saturating.rs | 9 --------- 2 files changed, 40 deletions(-) diff --git a/traits/src/ops/checked.rs b/traits/src/ops/checked.rs index a2df6d1..45e6716 100644 --- a/traits/src/ops/checked.rs +++ b/traits/src/ops/checked.rs @@ -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, but there are more pros than cons IMO : -// - These are methods, so users still have to be explicit about their intent; -// - Wrapping 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 to implement PrimInt. -impl CheckedAdd for Wrapping where Wrapping: Add>{ - #[inline] - fn checked_add(&self, v: &Self) -> Option { - self.0.checked_add(&v.0).map(Wrapping) - } -} -impl CheckedSub for Wrapping where Wrapping: Sub> { - #[inline] - fn checked_sub(&self, v: &Self) -> Option { - self.0.checked_sub(&v.0).map(Wrapping) - } -} -impl CheckedMul for Wrapping where Wrapping: Mul>{ - #[inline] - fn checked_mul(&self, v: &Self) -> Option { - self.0.checked_mul(&v.0).map(Wrapping) - } -} -impl CheckedDiv for Wrapping where Wrapping: Div> { - #[inline] - fn checked_div(&self, v: &Self) -> Option { - self.0.checked_div(&v.0).map(Wrapping) - } -} diff --git a/traits/src/ops/saturating.rs b/traits/src/ops/saturating.rs index 2a4f711..e9db749 100644 --- a/traits/src/ops/saturating.rs +++ b/traits/src/ops/saturating.rs @@ -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 Saturating for Wrapping { - #[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)) } -}