Member-only story
Rust Adventures: Conditional flow: Enum, Pattern Matching and If-Let.
Hi, the Rust Adventure continues!
Today we are going to discuss conditional flow in Rust and how it helps the language to solve some complex problems with simple solutions.
Introduction
I would like to start with Pattern Matching.
Pattern Matching is the act to resolve a sequence of tokens into some pattern. It’s a very broad explanation with many applications. I think the most know pattern matching is Regular Expression.
The Regular Expression is a special type of Pattern Matching called Sequence Patterns, because it works over a text like it was a Time Series using some kind of Backtracking algorithm to identify the patterns distributed over the target.
The Tree Patterns is used to describe a structured data that some languages utilizes even in their syntax. The Clojure language treats its own code as data and because of that you create macros that are interpreted in runtime.
Elixir brings an very interesting approach, the symbol “=” is not an assignment of a variable value, but instead is a pattern match. When you find “=” in Elixir code it’ll try to find anything in the left that the right value could fit. So the following code is completely normal.