easy_proc_macro

Crates.ioeasy_proc_macro
lib.rseasy_proc_macro
version0.1.0
sourcesrc
created_at2021-02-11 00:20:40.11198
updated_at2021-02-11 00:20:40.11198
descriptionRust's last proc-macro crate.
homepage
repositoryhttps://github.com/danii/easy_proc_macro.git
max_upload_size
id353604
size42,948
Daniel (danii)

documentation

README

Easy Procedural Macro

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.

Nightly Only Features

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.

Better Error Messages

Provides error messages that point at the actual incorrect code rather than the procedural macro invokation.

Stable

cannot borrow token as mutable, as it is not declared as mutable, pointing towards #[easy_proc_macro]. in this macro invocation, pointing towards my_stringify!(value, 12).

Nightly

cannot borrow token as mutable, as it is not declared as mutable, pointing towards token. in this macro invocation, pointing towards my_stringify!(value, 12).

Thanks to the proc_macro_diagnostic api.

Commit count: 13

cargo fmt