5 Hiding information and creating mini-DSLs with function-like macros

This chapter covers

  • Hiding information to improve code
  • Using function-like macros to modify and extend code
  • Using function-like macros to manipulate structs and functions
  • Debugging macros by getting the compiler or IDE to help you
  • Writing DSLs with flexible function-like macros
  • Deciding what macro fits a use case

The third and final type of procedural macro is the function-like macro, which—unlike the other two—is not limited to annotating structs, enums, and the like. Here, two examples will demonstrate its power. In our first example, we will stay close to familiar grounds by sticking to manipulating structs. Wilder experiments can wait until later in this chapter ...

Get Write Powerful Rust Macros now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.