3 ms·
I think the Result type is quite easy to understand, and it's central to Rust error handling strategy. The main difficulty is we also have to understand the pu
by ngrilly 7y ago
I think the Result type is quite easy to understand, and it's central to Rust error handling strategy.
The main difficulty is we also have to understand the purpose of the dyn keyword and why the Error must be boxed.
Anyone writing serious Rust will have to learn this sooner or later, but maybe this is a lot to learn "upfront" :-)
- 0815test 7y ago> The main difficulty is we also have to understand the purpose of the dyn keyword and why the Error must be boxed. Box<dyn Trait> is just an owning opaque pointer to something that implements the Trait interface. This kind of stuff is done all the time in C/C++ because it's just so darn useful, even though it requires a bunch of boilerplate code to make it work properly. (It's also arguably implied in the semantics of other languages, even though it's not directly marked in the code.) In Rust, it's just a line of code and the compiler provides checks that ensure you're writing something reasonable. (And of course you can dispense with the whole boxing mechanism when it's not needed, same as in C.)