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

Chapter 9 - Compiler Plugins

Macros offer only limited forms of code generation, which is why other mechanisms have been invented and many are being designed. Most of these work only on nightly compiler.

Compiler plugins enable a wider range of compile-time computation. They are currently being used for extending compile-time validation: code linters, database schema checkers, and many others. They are pieces of Rust code, which are linked to the compiler process by special annotations.

Custom derives (structure and function annotations) are widely used in popular libraries such as the Diesel ORM and the serialization library, Serde. That's why they were quickly stabilized in late 2016 in the form of macros 1.1, and those libraries can therefore ...

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