edit: there was an RFC for this and it has been rejected. Short Macro Invocation Syntax: m!123 and m!"abc" by m-ou-se · Pull Request #3267 · rust-lang/rfcs · GitHub
Rust parses macros by expecting the following sequence:
TokenTree::Ident(them)TokenTree::Punct('!')(the )TokenTree::Group.
You can invoke macros in 3 forms, which are TokenTree::Group:
m!()m![]m!{}
I believe there is no reason why the 3rd TokenTree must be a TokenTree::Group specifically? Removing this restriction will allow us to write more expressive macros when the macro input itself is very simple, (by dropping parentheses)
Some ideas off the top of my head:
bigint!100ee4to create a large numberf!"my name is {name}"python-like f-stringso!"heap-allocated string"d!"dedented string literal"could be written in user-code and be ergonomic enough to totally replace the RFC RFC: Dedented String Literals by nik-rev · Pull Request #3830 · rust-lang/rfcs · GitHublen!10km + len!50ftcould be nice. andcss!100px + css!4remcolor!ff00aaregex!"\d{3}-\d{2}-\d{4}".search(str)compile-time regexenv!MY_ENV_VARuuid!"550e8400-e29b-41d4-a716-446655440000"parses the UUID at compile-timeicon!"svgs/loading.svg"parses the SVG file at compile-time and expands to anIcon- stuff like
c!"c-string"andb!'?'byte chars could be implemented in user-code - For
TokenTree::PunctI thought aboutsyn'sToken![,]macro and how it could be written asToken!,but that doesn't look right so maybe forbidTokenTree::Punct
The input of the macros is still TokenStream with a single TokenTree::Literal or TokenTree::Ident