4 Making fields public with attribute macros

This chapter covers

  • Understanding the differences between derive macros and attribute macros
  • Finding field information in the abstract syntax tree
  • Retrieving fields by using matching
  • Retrieving fields with a custom struct
  • Retrieving fields with a custom struct and a Parse implementation
  • Adding multiple outputs in quote
  • Debugging macros with log statements
  • Understanding the no-panic crate

Rust likes to hide information. A function, struct, or enum is private by default, and the same goes for the fields of a struct. This is very sensible, though occasionally slightly annoying when you have a struct that has a lot of fields that are better off being public. Data Transfer Objects (DTOs) are a ...

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.