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

Summary

In this chapter, we covered many of the advanced macro features of Rust. They allow a Rust programmer to run arbitrary Rust code at compile time for various effects:

  • To generate Rust code based on some outside environmental state (such as database tables, time of date, and so on)
  • To decorate structures with custom attributes, generating arbitrary code for them at compile time
  • To create new linter plugins for making additional code checking passes that Rust itself does not support

Many of these features require the nightly version of the Rust compiler. There's a workaround via a code generation library called syntex, which enables many uses of nightly macros to work on the stable compiler, but it is slightly awkward to use.

The Rust ...

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