From the course: Rust Essential Training

Unlock the full course today

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

Match with default placeholder

Match with default placeholder - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Match with default placeholder

- [Instructor] The match operator can be used to evaluate more than just enums. To demonstrate that, let's initialize a variable named my number and assign it the value one, which will be stored as a u8 by using the suffix notation to specify its data type. Next, we'll create a match expression to evaluate my number. As an unsigned integer, it's first possible value is zero. And for that case, let's return a string literal that says zero. Similar to an if else expression, we can use match expressions to return a value based on the selected case. So, let's capture that return value by assigning it to a variable named result. And by doing that, we're changing it from an expression to a statement. So we'll need to add a semi-colon after the match block. Let's also add a print statement after the match block to display that return value. Now, let's continue filling out the match arms to handle the remaining possibilities.…

Contents