Join Abhiram Ravikumar for an in-depth discussion in this video Recoverable errors with Result demonstration, part of First Look: Rust.
- [Instructor] Let's now code for both these scenarios.…Declare a new variable, foo, and assign it…to the match operation on F, which is our file handle.…So now recall that we have two variants here,…the okay and the error.…When the result is okay,…let's return the inner file value out of the okay variant.…Okay, just the file,…and just return this file to the outer one.…
And then there's the error.…After the match is successful,…we can then use the file handle for reading or writing.…If we get an error value from the file open,…let's call the panic macro.…So here, to call a function, let's use curly braces…and then say panic, file was not found.…And top it off with a semicolon here,…and then a comma here, and then a semicolon here,…because it's a statement.…
If there's no file named hello.txt…in our current directory and we run this code,…we'll see that the panic macro gets invoked,…and this system cannot find the file specified.…Let's go ahead and do that.…So let's see Cargo run.…So as you can see, the code panicked at line number eight,…
- 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.