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

Macros

Rust has support for several forms of metaprogramming, which means writing programs that write programs. It can be a very powerful technique that helps surpass limitations of the language itself. It's a rather challenging way to program, however, and requires much more care and consideration than writing regular functions.

The oldest and most stable form of metaprogramming in Rust is syntactic macros. We'll cover those in this chapter.

This chapter will cover the following topics:

  • Introduction to metaprogramming
  • Dissecting println!
  • Macro keywords
  • Repeating constructs
  • Building our own macros

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