Creating procedural macros

We have seen what standard macros can do for our crate. We can create complex compile-time code that can both reduce the verbosity of our code, making it more maintainable, and improve the performance of the final executable by performing operations at compile time instead of at runtime.

Nevertheless, standard macros can only do so much. With them, you can only modify some of the Rust grammar token processing, but you are still bound to what the macro_rules!{} macro can understand. This is where procedural macros, also known as macros 1.1 or custom derives, come into play.

With procedural macros, you can create libraries that will be called by the compiler when deriving their name in some structure or enumeration. You can effectively create a custom trait, derive.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.158.32