Property-like Macro Syntax

I am wondering if it is possible to give macros a property-like syntax. This would have no change on the object, it would just be a syntactical improvement.

{param1}.{macro}!({param2}) would be equivalent to {macro}!({param1}, {param2}).

For example, I recently wrote a macro to check if a value is in a set of values or ranges: is_in!(value, 1..=16, 19, 21..23). However, I think the following syntax would look much better value.is_in!(1..=16, 19, 21..23).

As far as I am aware, there is no way to have macros as property or trait methods, so there would be no ambiguity or confusion as to what is going on when someone encounters the suggested syntax.

My understanding is that this forum is the formal process for suggesting a change to the Rust programming language. If I am incorrect, please direct me to the proper place to do that.

Thank you for your time and consideration.

This is known as postfix macros.

An old thread can be found here.

2 Likes