#![allow(clippy::needless_doctest_main)]
#![allow(clippy::unknown_clippy_lints)]
pub trait ConsTuple {
type Flattened;
fn flattened(self) -> Self::Flattened;
}
macro_rules! cons_tuple_ty {
($lhs:ident) => { ($lhs,) };
($lhs:ident, $($tail:ident),*) => { ($lhs, cons_tuple_ty!($($tail),*)) };
}
macro_rules! impl_cons_tuple {
($lhs:ident) => {
#[allow(non_snake_case)]
impl<$lhs> ConsTuple for ($lhs,) {
type Flattened = ($lhs,);
fn flattened(self) -> Self::Flattened {
self
}
}
};
($lhs:ident, $($tail:ident),+) => {
#[allow(non_snake_case)]
impl<$lhs, $($tail),+> ConsTuple for cons_tuple_ty!($lhs, $($tail),+) {
type Flattened = ($lhs, $($tail),+);
fn flattened(self) -> Self::Flattened {
let (lhs, rhs) = self;
let ($($tail, )+): ($($tail, )+) = rhs.flattened();
(lhs, $($tail),+)
}
}
};
}
impl_cons_tuple!(T1);
impl_cons_tuple!(T1, T2);
impl_cons_tuple!(T1, T2, T3);
impl_cons_tuple!(T1, T2, T3, T4);
impl_cons_tuple!(T1, T2, T3, T4, T5);
impl_cons_tuple!(T1, T2, T3, T4, T5, T6);
impl_cons_tuple!(T1, T2, T3, T4, T5, T6, T7);
impl_cons_tuple!(T1, T2, T3, T4, T5, T6, T7, T8);
#[macro_export]
macro_rules! join {
(, $e:expr) => { ($e(),) };
(, $e:expr, $($tail:expr),+) => { rayon::join($e, || join!(, $($tail),+)) };
($($e:expr),+) => { {
use $crate::ConsTuple;
join!(, $($e),+).flattened()
} };
}
#[test]
fn test_join() {
let (a, b, c) = join!(
|| (1..=100).count(),
|| (101..=200).count(),
|| (201..=300).count()
);
assert_eq!(a + b + c, 300);
}