Rust's last proc-macro crate.
Easy Procedural Macro is a procedural macro that allows you to create procedural macros without having to make your own proc-macro = true
crate.
Getting started is fairly easy. Just slap #[easy_proc_macro::easy_proc_macro]
ontop of any old macro definition, and boom, it becomes a procedural macro. Not much might have changed on the surface, but your macro has just gained a super power.
That super power being token manipulation blocks! Adding a token manipulation block to your macro is pretty straight forward. Just write a normal block with a dollar sign in front as if it was some special macro syntax, like so; ${/* ... */}
. Code inside these blocks will be ran at compile time, and operate upon Rust's token's directly, allowing your macros to do a whole lot more than just advanced Ctrl + C
+ Ctrl + V
.
Tokens you access inside a token manipulation block will be a string representation, allowing you to modify them to your heart's extent. The value a token manipulation block resolves to must implement ToString
, or be a String
or &str
(both implement ToString
). The returned value is what the token manipulation block will expand too.
This crate took great care to be able to be compiled on the Rust stable compiler, but there's some things that the Rust stable compiler just can't provide. Hence why these features are only available on a nightly compiler with the nightly
feature enabled on this crate.
Provides error messages that point at the actual incorrect code rather than the procedural macro invokation.
Thanks to the proc_macro_diagnostic
api.