This is not possible due to macro hygiene. Any identifier entered into the macro body is guaranteed to be different from any identifier on the macro invocation site. You must provide all the identifiers yourself, which somewhat does not match the purpose of the macro:
impl_a_method!(MyType, (foo, bar, baz), { MyType { foo: foo.blah(), bar: bar.bloo(), baz: baz.floozy(), } })
This is done using this macro:
macro_rules! impl_a_method( ($obj:ty, ($_foo:ident, $_bar:ident, $_baz:ident), $body:expr) => ( fn a_method($_foo: Foo, $_bar: Bar, $_baz: Baz) -> $obj { $body } ) )
The only thing you really save here is write the parameter types of the method.
source share