3 ms·
There actually is a way to do that, which is to return Results, with error types that implement From so the nested errors can be "wrapped" in the generic ones,
by eridius 9y ago
There actually is a way to do that, which is to return Results, with error types that implement From so the nested errors can be "wrapped" in the generic ones, and then you can just use the ? postfix operator as an alternative to unwrapping in order to bubble up the errors.
If you're designing your own errors then there's some boilerplate you need to allow for the error wrapping, though you can always take the cheap way out and use Box<Error> as your error type (as any error can be wrapped in that).
And there's an RFC that's been accepted (https://github.com/rust-lang/rfcs/blob/master/text/1937-ques-in-main.md https://github.com/rust-lang/rfcs/blob/master/text/1937-ques...) to allow main to return a Result, so you can use the ? operator in main, which will let you avoid even more unwraps, especially in example code.