Crates.io | easy_proc_macro |
lib.rs | easy_proc_macro |
version | 0.1.0 |
source | src |
created_at | 2021-02-11 00:20:40.11198 |
updated_at | 2021-02-11 00:20:40.11198 |
description | Rust's last proc-macro crate. |
homepage | |
repository | https://github.com/danii/easy_proc_macro.git |
max_upload_size | |
id | 353604 |
size | 42,948 |
Rust's last proc-macro crate.
Easy Procedural Macro is a procedural macro crate that, well, allows you to create procedural macros without having to create a whole dedicated crate for the macros. Hence why this is Rust's last proc-macro crate.
Getting started is fairly easy. Just slap #[easy_proc_macro::easy_proc_macro]
(or import it first if you prefer) ontop of any old macro definition, and boom, it becomes a procedural macro. Not much has 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; ${/* ... */}
. The 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, allowing you to modify the tokens to your heart's extent. The value a token manipulation block resolves to must implement ToString
, or a String
or &str
. The 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.