The match operator allows you to compare a value against a series of patterns and execute code based on the matched condition.
- [Instructor] Let's look at how pattern matching…and the match expression makes it easy…to run different code for different values…Rust has an extremely powerful control operator called match…that allows us to compare a value…against a series of patterns…and then execute code based on which pattern it matches.…Patterns can be made of both literal values,…variable names, wildcards and many other things.…The power of match comes from the expressiveness…of the patterns and the compiler checks…that all possible cases handle.…
Let's create a new project and call it patterns.…Let's navigate into the project,…let's open our main dot RS file,…take off the printLN statement here.…Let's define a new variable called name,…that is of string type.…
And then name it ram.…Now ram, here, has only three characters.…Therefore, if you want to get a character…at index four, it's not going to work.…So right here, there's a problem.…Given any index, we either get a value,…or don't get any value at all.…That's why, in Rust, getting a character…
- Installing Rust
- Data types
- Adjusting memory allocation
- Setting up race conditions
- Working with functions
- Exploring references and borrowing
- Using structs
- Method syntax
- Demonstrating recoverable errors with Result
- Working with enums
- Getting user input
Skill Level Beginner
Programming Foundations: Data Structureswith Simon Allardice2h 29m Intermediate
1. Hello, Rust!
2. Basic Programming Concepts
3. Ownership in Rust
4. Data Handling and Pattern Matching in Rust
5. Error Handling
6. Sample Rust Project: The Guessing Game
Next steps1m 14s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.