Returning Result or Option will always follow a certain pattern that generates a lot of boilerplate code—especially for uncertain operations such as reading or creating files and searching for values. In particular, the pattern produces either code that uses early returns a lot (remember goto?) or nested statements, both of which produce code that is hard to reason about. Therefore, early versions of the Rust library implemented a try! macro, which has been replaced with the ? operator as a quick early return option. Let's see how that influences the code.
Resilient programming
How to do it...
Follow these steps to write more resilient programs:
- Create a new project with cargo new resilient-programming and open...