Implementing complex derivations

The syn and quote crates allow for really complex derivations. And, not only that, we do not necessarily need to derive a trait; we can implement any kind of code for the given structure or enumeration. This means that we can derive builder patterns, as we saw in the previous chapter, which will actually create a new structure or Getters and Setters for our structure.

That is what we are going to do for our next example. We will create structures and give them some methods to get and set the fields of the structure. In Rust, convention says that Getters should have the name of the field, without any prefix or a suffix such as get. So, for a field named foo, the Getter should be foo(). For mutable Getters

Get Rust High Performance 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.