Skip to content

Fix CI errors about unused-macro-rules #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 8 additions & 22 deletions src/stream/product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use core::ops::Mul;
use core::num::Wrapping;
use crate::stream::stream::StreamExt;

macro_rules! integer_product {
(@impls $one: expr, $($a:ty)*) => ($(
macro_rules! num_product {
($one:expr, $($a:ty)*) => ($(
impl Product for $a {
fn product<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Self>+ 'a>>
where
Expand All @@ -46,32 +46,18 @@ macro_rules! integer_product {
}
}
)*);
}

macro_rules! integer_product {
($($a:ty)*) => (
integer_product!(@impls 1, $($a)*);
integer_product!(@impls Wrapping(1), $(Wrapping<$a>)*);
num_product!(1, $($a)*);
num_product!(Wrapping(1), $(Wrapping<$a>)*);
);
}

macro_rules! float_product {
($($a:ty)*) => ($(
impl Product for $a {
fn product<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Self>+ 'a>>
where S: Stream<Item = $a> + 'a,
{
Box::pin(async move { stream.fold(1.0, |a, b| a * b).await } )
}
}
impl<'a> Product<&'a $a> for $a {
fn product<'b, S>(stream: S) -> Pin<Box<dyn Future<Output = Self>+ 'b>>
where S: Stream<Item = &'a $a> + 'b,
{
Box::pin(async move { stream.fold(1.0, |a, b| a * b).await } )
}
}
)*);
($($a:ty)*) => (
float_product!($($a)*);
float_product!($(Wrapping<$a>)*);
num_product!(1.0, $($a)*);
);
}

Expand Down
30 changes: 8 additions & 22 deletions src/stream/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use crate::stream::stream::StreamExt;
use core::num::Wrapping;
use core::ops::Add;

macro_rules! integer_sum {
(@impls $zero: expr, $($a:ty)*) => ($(
macro_rules! num_sum {
($zero:expr, $($a:ty)*) => ($(
impl Sum for $a {
fn sum<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Self>+ 'a>>
where
Expand All @@ -46,32 +46,18 @@ macro_rules! integer_sum {
}
}
)*);
}

macro_rules! integer_sum {
($($a:ty)*) => (
integer_sum!(@impls 0, $($a)*);
integer_sum!(@impls Wrapping(0), $(Wrapping<$a>)*);
num_sum!(0, $($a)*);
num_sum!(Wrapping(0), $(Wrapping<$a>)*);
);
}

macro_rules! float_sum {
($($a:ty)*) => ($(
impl Sum for $a {
fn sum<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Self> + 'a>>
where S: Stream<Item = $a> + 'a,
{
Box::pin(async move { stream.fold(0.0, |a, b| a + b).await } )
}
}
impl<'a> Sum<&'a $a> for $a {
fn sum<'b, S>(stream: S) -> Pin<Box<dyn Future<Output = Self> + 'b>>
where S: Stream<Item = &'a $a> + 'b,
{
Box::pin(async move { stream.fold(0.0, |a, b| a + b).await } )
}
}
)*);
($($a:ty)*) => (
float_sum!(@impls 0.0, $($a)*);
float_sum!(@impls Wrapping(0.0), $(Wrapping<$a>)*);
num_sum!(0.0, $($a)*);
);
}

Expand Down