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.
Result<T, E> enum - Rust Tutorial
From the course: Rust Essential Training
Result<T, E> enum
- [Instructor] Many runtime errors are recoverable meaning they're not so serious we need to panic and terminate the program, we can still do something to smoothly handle the problem and continue onwards. For example, if our program tries to access a file that does not exist that's a problem. We might resolve it by letting the user know and giving them the opportunity to select a different file path or our program might choose to create the missing file. It just depends on what we need the program to do. To facilitate handling those types of recoverable errors, the Russ standard library defines the result enum with two variants, okay and error representing the result of an operation that can either succeed or fail. The okay variant stores the value for the success as generic type T and the error variants stores the error value as generic type E. Like the option enum, the result enum is common enough to be included…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.