I want to implement a trait for tuples, so I'm using a macro.
For tuples I want to apply my trait operator element-wisely.
i.e
(self.0.foo(other.0), self.1.foo(other.1), self.2.foo(other.2))
But I don't get how to actually implement this with macro.
trait Foo {
fn foo(self, other: Self) -> Self;
}
macro_rules! impl_tuple {
($($t:tt)+) => {
impl<$($t,)+> Foo for ($($t,)+)
where
$($t: Foo,)+
{
fn foo(self, other: Self) -> Self {
let ($($t,)+) = self;
let ($($t,)+) = other;
// ???
}
}
};
}
impl_tuple!(A B C D E F G H I J);
impl_tuple!(A B C D E F G H I);
impl_tuple!(A B C D E F G H);
impl_tuple!(A B C D E F G);
impl_tuple!(A B C D E F);
impl_tuple!(A B C D E);
impl_tuple!(A B C D);
impl_tuple!(A B C);
impl_tuple!(A B);
impl_tuple!(A);