From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Match operator

Match operator - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Match operator

- [Narrator] In rust, enums are commonly used in match expressions, which can control the flow of a program. Similar to a sequence of, if else expressions the match operator compares a given value to a series of patterns to determine which code to execute, similar to a switch statement in several other programming languages. A good analogy for the match operator is a coin sorting machine which uses a ramp with a series of sequentially larger holes to sort coins, based on the relative size. If you drop a penny into the sorter it will roll pass the first hole because a penny is larger than a dime. And then when it reaches the second hole which is sized for a penny, it will fall through to be collected in a container for pennies below. If you drop a quarter into the sorter it will roll past all the smaller holes until it reaches the quarter size slot, and then it will fall through. To demonstrate that concept in rust,…

Contents