O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Code generation as a workaround

As mentioned before, compiler plugins are not a stable feature, but they are useful enough so that people want to use their features. There's a workaround that works already in the stable branch: code generation via a library called libsyntex. It works by essentially bundling the whole Rust compiler in a library and using it in order to implement the compiler plugins. This is not a drop-in replacement for the compiler plugins as they are in the nightly Rust; many small changes to the code base need to be done in order for the code generation method to work.

In practice this works by moving any code modules with compiler plugin functionality in a template file ending with .in. A separate build script (usually ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required