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

Basics of compiler plugins

The macros we saw in the previous chapter transformed a syntax into another syntax at compile time. That is a neat tool since it allows many forms of compile-time operations while providing a clean and stable API. However, there are a great number of desirable compile-time things we cannot do just by text manipulations. Here are some:

  • Extra code validation checks (lints).
  • Compile-time validations: database schema checks, hostname validations.
  • Generating code depending on the environment. For example, creating data models from live database tables, filling in data structures from the environment, optimizing runtime performance by computing expensive things at compile time, and so on.

Whereas macros-by-example from ...

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