Function arity dependent macros

I am still learning Rust and afaiu, with the macro_rules! syntax there is no way to match on the arity of a passed function, or is there a clever way to compose multiple macro's to get this behavior?

I am trying to DRY on a common pattern where I want to pass in a function that sometimes takes self. The simplest solution is to have all functions that will be passed to the macro to take an potentially unused self, but are there any other, more elegant solutions?

Thank you!

Well, given an invocation like some_macro!(a_function), you can't determine the arity of a_function; at least, not within the macro itself. Without an example of exactly what you're trying to accomplish, I can't be certain if there's anything else you can do or not.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.