struct X {}
macro_rules! test {
($tmpl: path) => {
impl $tmpl<usize> for X {
type Output = ();
fn add(self, b: usize) -> () {}
}
};
}
test!(std::ops::Add);
This code doesn't compile:
error: expected `::`, found keyword `for`
--> src/lib.rs:5:27
|
5 | impl $tmpl<usize> for X {
| ^^^ expected `::`
...
12 | test!(std::ops::Add);
| -------------------- in this macro invocation
|
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
I really can't figure out how to fix this; the LLMs don't emit anything useful. I want to be able to implement multiple operations and I cannot pass in std::ops::Add - because in my real code I have more than one types that I want to put inside std::ops::Add, in the same macro expansion (in this example I only showed one).