From e4b3e64739ff41b9c0f34be9483b99da53674a10 Mon Sep 17 00:00:00 2001 From: Johannes Muenzel Date: Thu, 18 Dec 2014 19:17:37 -0500 Subject: [PATCH] Reintroduce CheckedAddressDiff now that multidispatch works --- src/address.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/address.rs b/src/address.rs index 8eab3f0..ff4d5e6 100644 --- a/src/address.rs +++ b/src/address.rs @@ -25,6 +25,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +use std::num::Int; + // The idea here is that it doesn't make sense to add two addresses, but it // does make sense to add an address and an "address-difference". (If this // is too annoying to work with we should let it go.) @@ -50,30 +52,20 @@ impl Add for AddressDiff { } } -// rustc doesn't seem to like having multiple implementations of Add for -// Address. I believe this is a Rust bug (possibly resolved by "associated -// types" RFC?). Or I wrote it wrong. Anyway, here's some living dead code: -/* -#[deriving(PartialEq, Eq, PartialOrd, Ord)] +#[deriving(Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct CheckedAddressDiff(u16); impl Add for Address { - fn add(&self, &CheckedAddressDiff(rhs): &CheckedAddressDiff) -> Address { - let &Address(lhs) = self; + fn add(self, CheckedAddressDiff(rhs): CheckedAddressDiff) -> Address { + let Address(lhs) = self; // We probably don't want to overflow when doing arithmetic in our own // code. - debug_assert!({ - match lhs.checked_add(&rhs) { - None => false, - _ => true - } - }); + debug_assert!(lhs.checked_add(rhs).is_some()); Address(lhs + rhs) } } -*/ impl Address { pub fn to_u16(&self) -> u16 {