October 2018
Beginner
180 pages
4h 48m
English
When we call a function that returns Result, the return value is—as requested—a Result, rather than the data type we really need. There are several ways of working with that, depending on our specific needs.
The simplest way to deal with a Result is to use the ? operator, which extracts the stored value from a successful Result, or returns a Result containing the error value if the Result it's looking at indicates an error. Because ? might return from the current function in the same way that a return statement would, ? can only be used in functions that themselves return Result and use the same data type to represent errors. Using ? looks like this:
let mut cons: Constrained = new_constrained(0, 10, 5)?; ...
Read now
Unlock full access