From b3f005fe0945994cd16740a128f73722c299efbb Mon Sep 17 00:00:00 2001 From: Andy Grover Date: Mon, 20 Feb 2017 13:12:58 -0800 Subject: [PATCH] Move NewtypeSum and Newtype Product out of unstable Since iter::Sum and iter::Product have been in stable since 1.12, we can move NewtypeSum and NewtypeProduct from std_unstable.rs to lib.rs. Signed-off-by: Andy Grover --- newtype_derive/src/lib.rs | 50 ++++++++++++++++++++++++++++++ newtype_derive/src/std_unstable.rs | 50 ------------------------------ 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/newtype_derive/src/lib.rs b/newtype_derive/src/lib.rs index b322ed9..1d613ec 100644 --- a/newtype_derive/src/lib.rs +++ b/newtype_derive/src/lib.rs @@ -1169,3 +1169,53 @@ macro_rules! NewtypeUpperHex { newtype_fmt! { UpperHex, $name } }; } + +#[macro_export] +macro_rules! NewtypeProduct { + ($arg:tt $(pub)* struct $name:ident(pub $t0:ty);) => { + NewtypeProduct! { $arg struct $name($t0); } + }; + + (() $(pub)* struct $name:ident($t0:ty);) => { + impl ::std::iter::Product<$name> for $name { + fn product(iter: I) -> Self + where I: Iterator { + $name(iter.map(|e| e.0).product::<$t0>()) + } + } + }; + + ((&Self) $(pub)* struct $name:ident($t0:ty);) => { + impl<'a> ::std::iter::Product<&'a $name> for $name { + fn product(iter: I) -> Self + where I: Iterator { + $name(iter.map(|e| &e.0).product::<$t0>()) + } + } + }; +} + +#[macro_export] +macro_rules! NewtypeSum { + ($arg:tt $(pub)* struct $name:ident(pub $t0:ty);) => { + NewtypeSum! { $arg struct $name($t0); } + }; + + (() $(pub)* struct $name:ident($t0:ty);) => { + impl ::std::iter::Sum<$name> for $name { + fn sum(iter: I) -> Self + where I: Iterator { + $name(iter.map(|e| e.0).sum::<$t0>()) + } + } + }; + + ((&Self) $(pub)* struct $name:ident($t0:ty);) => { + impl<'a> ::std::iter::Sum<&'a $name> for $name { + fn sum(iter: I) -> Self + where I: Iterator { + $name(iter.map(|e| &e.0).sum::<$t0>()) + } + } + }; +} diff --git a/newtype_derive/src/std_unstable.rs b/newtype_derive/src/std_unstable.rs index 7feb7b9..4db5e08 100644 --- a/newtype_derive/src/std_unstable.rs +++ b/newtype_derive/src/std_unstable.rs @@ -28,56 +28,6 @@ macro_rules! NewtypeOne { }; } -#[macro_export] -macro_rules! NewtypeProduct { - ($arg:tt $(pub)* struct $name:ident(pub $t0:ty);) => { - NewtypeProduct! { $arg struct $name($t0); } - }; - - (() $(pub)* struct $name:ident($t0:ty);) => { - impl ::std::iter::Product<$name> for $name { - fn product(iter: I) -> Self - where I: Iterator { - $name(iter.map(|e| e.0).product::<$t0>()) - } - } - }; - - ((&Self) $(pub)* struct $name:ident($t0:ty);) => { - impl<'a> ::std::iter::Product<&'a $name> for $name { - fn product(iter: I) -> Self - where I: Iterator { - $name(iter.map(|e| &e.0).product::<$t0>()) - } - } - }; -} - -#[macro_export] -macro_rules! NewtypeSum { - ($arg:tt $(pub)* struct $name:ident(pub $t0:ty);) => { - NewtypeSum! { $arg struct $name($t0); } - }; - - (() $(pub)* struct $name:ident($t0:ty);) => { - impl ::std::iter::Sum<$name> for $name { - fn sum(iter: I) -> Self - where I: Iterator { - $name(iter.map(|e| e.0).sum::<$t0>()) - } - } - }; - - ((&Self) $(pub)* struct $name:ident($t0:ty);) => { - impl<'a> ::std::iter::Sum<&'a $name> for $name { - fn sum(iter: I) -> Self - where I: Iterator { - $name(iter.map(|e| &e.0).sum::<$t0>()) - } - } - }; -} - #[macro_export] macro_rules! NewtypeZero { (() $(pub)* struct $name:ident(pub $_t0:ty);) => {