Nested Match Result

I'm finished my first app in Rust, it's something very simple.
My query is not about specific code, it is rather on how to organize the code so as not to end up in a Match and Result hell.
I have calls to a REST API, opening, readings and writing in the serial port, split of strings, conversion of data types (parse), etc. and each of this returns a Result, so I have all nested.

For now I'm using unwrap for almost everything, but I understand that it's not the way

As you will see, I'm starting with Rust

Jose

It's recommended to return early with the error instead of the nested match. This chapter of the book would be helpful. The ? operator exists solely for this purpose. To read more about the underlying principle, searching "railway oriented programming" lists nice articles including the original (I guess) reference and the one with Rust code.

2 Likes

Thank you. Now I'm going to read it.

Greetings

Here [1], In the link you sent me , is very clear the explanation. Thanks

[1] Recoverable Errors with Result - The Rust Programming Language