In a previous recipe, we were using macros to generate almost arbitrary code, thereby reducing the amount of code to write. Let's dive deeper into this topic since this is a great way not only to reduce bugs but also to achieve consistent quality in code. One repetitive task that everyone should do is testing (especially if it's a public-facing API), and if we copy and paste those tests we expose ourselves to errors. Instead, let's see how we can generate boilerplate code with macros to stop repeating ourselves.
Don't Repeat Yourself
How to do it...
Automated testing with macros is only a few steps away:
- Run cargo new dry-macros --lib in Terminal (or PowerShell on Windows) and open the directory with...