inflearn logo

Elegant Rust Intermediate (4) - Pattern Matching

As the number of `match` branches increases, it can be easy to get confused about how to inspect the structure of a value and extract only the parts you need. In this course, you’ll learn how to destructure tuples, structs, enums, and slices directly, and how to use `if let`, `let else`, and match guards to express conditions concisely and accurately. You’ll also use examples to see whether values are moved or borrowed when references are handled as patterns.

1 learners are taking this course

Level Intermediate

Course period Unlimited

Rust
Rust
Rust
Rust

What you will gain after the course

  • You can handle all possible forms of values with match and destructuring patterns.

  • You can choose the syntax that best suits the situation: if let, let else, or while let.

  • Can read reference patterns and distinguish between moving and borrowing values.

Pattern syntax for reading value shapes and extracting the necessary parts

In Rust, match does more than just split code based on values. It extracts and names the inner values of tuples, structs, and enums, and also checks that no cases have been left unhandled. In this course, you will run short examples yourself and learn step by step, from the basic rules of patterns to how to combine conditions.

You’ll learn the following contents.

match and destructuring

Learn how to branch on values according to patterns and handle every case without omission. Destructure tuples, structs, enums, and slices, naming only the values you need. letAlso learn to distinguish patterns that can be used with let from those that may fail to match.

Match Guard Evaluation Order

Pattern expressions suited to the situation

Using if let, let else, while let, write code that focuses on a single case. Express conditions with OR patterns, ranges, match guards, and @ bindings, and check whether values are moved or borrowed when destructuring references. Finally, apply the syntax you learned to a small command-processing exercise.

Slice patterns

Comprehensive Practice: Writing Code to Interpret Commands

Write a function that distinguishes commands passed as strings using patterns, extracts the necessary values, and processes them. Verify through tests that all cases are handled without omission, and apply the destructuring and branching syntax learned earlier to actual code.

Things to Note Before Taking the Course

Practice Environment

  • Operating system and version (OS): Windows, macOS, Linux, etc.

  • Tools used: rustup, cargo, VS Code

  • PC specifications: No high-end hardware is required.

Learning Materials

  • Online Learning Materials

  • GitHub source code

Prerequisites and Important Notes

  • Recommended: Take the course “Introduction to and Practical Use of the Elegant Programming Language Rust.”

  • This is part of the intermediate Rust series lectures by Woowa.

Recommended for
these people

Who is this course right for?

  • Those who have learned Rust’s basic syntax but find it difficult to read or write complex match expressions

  • Those who want to reduce repetitive conditional-checking code when working with enum and struct values

  • Those who want to see through examples how ref, &, and match guards work in patterns

Need to know before starting?

  • Understanding Rust’s memory ownership model

  • Understanding the basics of Rust syntax

Hello
This is hatemogi

Career Verified

2,187

Learners

171

Reviews

27

Answers

4.7

Rating

10

Courses

I am a backend developer with a strong interest in functional programming. I have led development teams as a development team manager at Kakao, a principal engineer at NHN, and a lead at LINE+. I also worked as the head of the development team at an AI startup called Dnotitia, where I worked on projects using Rust.

Curriculum

All

12 lectures ∙ (1hr 2min)

Published: 
Last updated: 

Reviews

Not enough reviews.
Please write a valuable review that helps everyone!

hatemogi's other courses

Check out other courses by the instructor!

Similar courses

Explore other courses in the same field!

Limited time deal

$6,600.00

40%

$8.80