Skip to content

danii/easy_proc_macro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Easy Procedural Macro

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.

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.

About

Rust's last proc-macro crate.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages