I am trying to nest macro calls to ease converting between rust and c ffi types.
The inner macro generates calls to conversion functions from type names like this:
macro_rules! type_conversion {
($arg_name:ident, bool, BOOL) => (crate::type_wrappers::type_conversion::convert_rust_bool($arg_name));
($arg_name:ident, BOOL, bool) => (crate::type_wrappers::type_conversion::convert_c_bool($arg_name));
}
The outer macro now uses this to generate further conversions. It basically works like this:
macro_rules! outer {
($arg_name:ident, $type1:ty, $type2:ty) => (type_conversion!($arg_name, $type1, $type2));
}
Now, when i try to use the outer macro like this:
fn outer() {
outer!(hello_world, bool, BOOL);
}
I get this Error:
error: no rules expected the token `bool`
--> src\type_wrappers\type_conversion.rs:252:77
|
202 | macro_rules! type_conversion {
| ---------------------------- when calling this macro
...
252 | ($arg_name:ident, $type1:ty, $type2:ty) => (type_conversion!($arg_name, $type1, $type2));
| ^^^^^^ no rules expected this token in macro call
...
256 | outer!(hello_world, bool, BOOL);
| ------------------------------- in this macro invocation
I cannot make sense out of this error, especially since CLions Macro expansion tool expands this into:
type_conversion!(hello_world , bool , BOOL )
Which is what i would expect and also, what the Error suggests.
Where is the Error in those Macros?
test!was meant to beouter!. I edited the question. - Erik Schulze