In this video, compare the generated secret number with the user’s guess using match operator and the Ordering enum.
- Now that we have the user input and the random number…we can compare them.…Let's go ahead and we can just go a little bit,…so let's say print ln, welcome to the guessing game.…And then let's generate the secret number right after that.…And then let's print out the secret number for our testing…before the user input sys, yes.…
Let me just delete this line and then now it's looking good.…The first thing we do is to bring…the ordering innum in to the scope.…Let's write use, S-T-D, double colon, C-M-P,…double colon, auditing.…Here the S-T-D is the main library standard…which in turn contains the cmp library,…the computer's own library.…So cmp is really a sub library inside std.…
Ordering is another innum just like this…but the variance of ordering are less,…greater, and equal.…These are the three outcomes that are possible…when you compare two values.…We'll use the match operator to compare the user…input guess with a generated secret number.…Scroll down, once you've got the guess, just say match…and guess, dot C-M-P and parse the secret number here.…
- 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 Structures (2014)with 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.