Skip to content

Commit e7f7d9e

Browse files
committed
Fix CI errors about unused-macro-rules
float_product and float_sum had unused rules, because they weren't successfully using their second branch, and weren't successfully defining wrapping types. Fix that, and in the process, unify the integer and float macros.
1 parent 264a712 commit e7f7d9e

File tree

2 files changed

+20
-46
lines changed

2 files changed

+20
-46
lines changed

src/stream/product.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use core::ops::Mul;
2727
use core::num::Wrapping;
2828
use crate::stream::stream::StreamExt;
2929

30-
macro_rules! integer_product {
31-
(@impls $one: expr, $($a:ty)*) => ($(
30+
macro_rules! num_product {
31+
($(($one:expr, $a:ty))*) => ($(
3232
impl Product for $a {
3333
fn product<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Self>+ 'a>>
3434
where
@@ -42,36 +42,23 @@ macro_rules! integer_product {
4242
where
4343
S: Stream<Item = &'a $a> + 'b,
4444
{
45-
Box::pin(async move { stream.fold($one, Mul::mul).await } )
45+
Box::pin(async move { stream.fold(&$one, Mul::mul).await } )
4646
}
4747
}
4848
)*);
49+
}
50+
51+
macro_rules integer_product {
4952
($($a:ty)*) => (
50-
integer_product!(@impls 1, $($a)*);
51-
integer_product!(@impls Wrapping(1), $(Wrapping<$a>)*);
53+
num_product!($((1, $a))*);
54+
num_product!($((Wrapping(1), Wrapping<$a>))*);
5255
);
5356
}
5457

5558
macro_rules! float_product {
56-
($($a:ty)*) => ($(
57-
impl Product for $a {
58-
fn product<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Self>+ 'a>>
59-
where S: Stream<Item = $a> + 'a,
60-
{
61-
Box::pin(async move { stream.fold(1.0, |a, b| a * b).await } )
62-
}
63-
}
64-
impl<'a> Product<&'a $a> for $a {
65-
fn product<'b, S>(stream: S) -> Pin<Box<dyn Future<Output = Self>+ 'b>>
66-
where S: Stream<Item = &'a $a> + 'b,
67-
{
68-
Box::pin(async move { stream.fold(1.0, |a, b| a * b).await } )
69-
}
70-
}
71-
)*);
7259
($($a:ty)*) => (
73-
float_product!($($a)*);
74-
float_product!($(Wrapping<$a>)*);
60+
num_product!($((1.0, $a))*);
61+
num_product!($((Wrapping::<$a>(1.0), Wrapping<$a>))*);
7562
);
7663
}
7764

src/stream/sum.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use crate::stream::stream::StreamExt;
2727
use core::num::Wrapping;
2828
use core::ops::Add;
2929

30-
macro_rules! integer_sum {
31-
(@impls $zero: expr, $($a:ty)*) => ($(
30+
macro_rules! num_sum {
31+
($(($zero:expr, $a:ty))*) => ($(
3232
impl Sum for $a {
3333
fn sum<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Self>+ 'a>>
3434
where
@@ -42,36 +42,23 @@ macro_rules! integer_sum {
4242
where
4343
S: Stream<Item = &'a $a> + 'b,
4444
{
45-
Box::pin(async move { stream.fold($zero, Add::add).await } )
45+
Box::pin(async move { stream.fold(&$zero, Add::add).await } )
4646
}
4747
}
4848
)*);
49+
}
50+
51+
macro_rules integer_sum {
4952
($($a:ty)*) => (
50-
integer_sum!(@impls 0, $($a)*);
51-
integer_sum!(@impls Wrapping(0), $(Wrapping<$a>)*);
53+
num_sum!($((0, $a))*);
54+
num_sum!($((Wrapping(0), Wrapping<$a>))*);
5255
);
5356
}
5457

5558
macro_rules! float_sum {
56-
($($a:ty)*) => ($(
57-
impl Sum for $a {
58-
fn sum<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Self> + 'a>>
59-
where S: Stream<Item = $a> + 'a,
60-
{
61-
Box::pin(async move { stream.fold(0.0, |a, b| a + b).await } )
62-
}
63-
}
64-
impl<'a> Sum<&'a $a> for $a {
65-
fn sum<'b, S>(stream: S) -> Pin<Box<dyn Future<Output = Self> + 'b>>
66-
where S: Stream<Item = &'a $a> + 'b,
67-
{
68-
Box::pin(async move { stream.fold(0.0, |a, b| a + b).await } )
69-
}
70-
}
71-
)*);
7259
($($a:ty)*) => (
73-
float_sum!(@impls 0.0, $($a)*);
74-
float_sum!(@impls Wrapping(0.0), $(Wrapping<$a>)*);
60+
num_sum!($((0.0, $a))*);
61+
num_sum!($((Wrapping::<$a>(0.0), Wrapping<$a>))*);
7562
);
7663
}
7764

0 commit comments

Comments
 (0)