I have a few macros that allows for "variadic" tuples. You pass a macro, bundle, and a backwards array slice of generics to the recurse_and_apply!()
macro or at least in this specific case. That macro then recurses and applys the bundle trait to the generics in the order of (A, B, C), (B, C), (C), and (). In theory it should work however it doesn't compile with the reason being conflicting implementations. I get these errors in this order.
conflicting implementations of trait `Bundle` for type `()`
conflicting implementation for `()`
conflicting implementations of trait `Bundle` for type `(_, _)`
conflicting implementation for `(_, _)`
conflicting implementations of trait `Bundle` for type `(_, _, _)`
conflicting implementation for `(_, _, _)`
conflicting implementations of trait `bundle::Bundle` for type `()`
conflicting implementation for `()`
conflicting implementations of trait `bundle::Bundle` for type `(_, _)`
conflicting implementation for `(_, _)`
conflicting implementations of trait `bundle::Bundle` for type `(_, _, _)`
conflicting implementation for `(_, _, _)`
And heres the code
pub trait Bundle {}
macro_rules! bundle {
( $( $item:ident ),* ) => {
impl<$( $item ),*> Bundle for ($( $item ),*) {}
};
}
macro_rules! recurse_and_apply {
( $macro:ident, [$head: tt] ) => {
$macro!{$head}
$macro!{}
};
( $macro:ident, [$head: tt, $( $tail:tt ),*] ) => {
recurse_and_apply!{$macro, [$( $tail ),*]}
$macro!{$head, $( $tail ),*}
};
}
recurse_and_apply!(bundle, [A, B, C]);
There is a temporary solution I have found with that being removing this line, $macro!{$head}
from the recurse_and_apply!()
macro. I have no idea why that works but it does. So my question to you the reader is how would I go about solving this issue. And please don't respond by saying to just use vectors instead I understand I can do that.