When we created custom macros, we had already seen pattern matching at play: a command was only executed if particular words were present before compilation. In other words, the macro system compares raw text as patterns before they become expressions or types. Consequently, creating a DSL is really easy. Defining a web request handler? Use method names in the pattern: GET, POST, HEAD. There is an endless variety, however, so let's see how we can define some patterns in this recipe!
Implementing matching with macros
How to do it...
By following these next few steps, you will be able to use macros:
- Run cargo new matching --lib in Terminal (or PowerShell on Windows) and open the directory with Visual Studio Code.
- In src...