I've created a Rust macro which expands to a function declaration.
macro_rules! build_fn
{
($name:tt) => {
pub fn $name(&self) -> Result<i32, Box<dyn Error>>
{
// <implementation>
Ok(0)
}
};
}
Is it possible to expand this so the macro can take variable parameters?
e.g.
($name:tt, /*$variable_args ? */) => {
pub fn $name(&self, /*$variable_args ? */) -> Result<i32, Box<dyn Error>>
{
// ...
Ok(0)
}
};
}
Since @ranfdev's answer is not currently compiling, I've fixed & simpified & extended it to support multiple types -- and it now runs in Rust stable:
Output:
See it on Playgroud!