As shown in the previous recipe, pattern matching is very useful with enums. However, there is more! Pattern matching is a construct that originates in functional languages and curtails much of the choice between conditional branches and the assignment of properties in struct that commonly follows. These steps are taken at once, reducing the amount of code on the screen and creating something akin to a higher-order switch-case statement.
Complex conditions with pattern matching
How to do it...
Just a few steps need to be followed in order to learn more about pattern matching:
- Create a new binary project using cargo new pattern-matching. This time, we'll run an actual executable! Again, open the project using Visual...