From 80f6f542abf8701de45010f5f29f4bfae74fe8cd Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Fri, 15 Jul 2016 07:55:44 -0700 Subject: Update to latest nightly Previous version of serde no longer worked; cargo packages were updated as a result. `Zero` and `One` traits were deprecated. Use of those was removed. The `Step` trait gained a lot more methods, and the index::$ty implementations were updated. --- src/index.rs | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'src/index.rs') diff --git a/src/index.rs b/src/index.rs index a4167e0d..61c39fd6 100644 --- a/src/index.rs +++ b/src/index.rs @@ -17,7 +17,7 @@ /// Indexing types and implementations for Grid and Line use std::fmt; use std::iter::Step; -use std::num::{One, Zero}; +use std::mem; use std::ops::{self, Deref, Add}; /// Index in the grid using row, column notation @@ -134,31 +134,15 @@ macro_rules! sub { } } -macro_rules! zero_one { - ($ty:ty, $construct:expr) => { - impl One for $ty { - fn one() -> $ty { - $construct(1) - } - } - - impl Zero for $ty { - fn zero() -> $ty { - $construct(0) - } - } - } -} - macro_rules! ops { ($ty:ty, $construct:expr) => { add!($ty, $construct); sub!($ty, $construct); - zero_one!($ty, $construct); deref!($ty, usize); forward_ref_binop!(impl Add, add for $ty, $ty); impl Step for $ty { + #[inline] fn step(&self, by: &$ty) -> Option<$ty> { Some(*self + *by) } @@ -180,6 +164,37 @@ macro_rules! ops { Some(0) } } + + #[inline] + fn steps_between_by_one(start: &$ty, end: &$ty) -> Option { + Step::steps_between(start, end, &$construct(1)) + } + + #[inline] + #[allow(unused_comparisons)] + fn is_negative(&self) -> bool { + self.0 < 0 + } + + #[inline] + fn replace_one(&mut self) -> Self { + mem::replace(self, $construct(0)) + } + + #[inline] + fn replace_zero(&mut self) -> Self { + mem::replace(self, $construct(1)) + } + + #[inline] + fn add_one(&self) -> Self { + *self + 1 + } + + #[inline] + fn sub_one(&self) -> Self { + *self - 1 + } } impl ops::AddAssign<$ty> for $ty { -- cgit v1.2.3-54-g00ecf