nop-macros
Procedural macros that do nothing, allowing attributes to be used as metadata.
Any code marked with the #[nop_macros::nop]
attribute
is passed through without modification.
Similarly, using #[derive(nop_macros::NopDerive)]
on a type does not generate any code or implement any traits.
Useful for source-code only metadata, readable by tools but ignored at runtime. I use this for configuring build-time source generation (see "Use Cases" below).
All macros can be used multiple times and renamed with pub use
.
Example
pub use nop as example1;
pub use nop_noargs as example2;
pub use nop as example3;
pub use NopDerive as DeriveExample1;
pub use NopDerive as DeriveExample2;
const BAR: u32 = 42;
assert_eq!;
assert_eq!;
assert_eq!;
Use Cases
I use this for generating source-code at build-time, configured by attributes on rust code.
An example of a build-time source generator that parses rust code is cbindgen. However, that project uses comments for configruation, which I want to avoid.
Build-time source generation is significantly more powerful and flexible than procedural macros. Maktlad has a blog post on this subject.
I recomend genco instead of quote for build-time quasiquoting. It preserves whitespace and supports languages besides rust.
I still use syn for parsing rust code.