2 ms·
There are plenty of cases where the Err alternatives of Result doesn't actually represent an error, just a case to be handled differently. For example the binar
by kccqzy 4y ago
There are plenty of cases where the Err alternatives of Result doesn't actually represent an error, just a case to be handled differently. For example the binary search function (https://doc.rust-lang.org/std/primitive.slice.html#method.binary_search https://doc.rust-lang.org/std/primitive.slice.html#method.bi...) returns an index of the insertion position when the search fails. That's not usually an error to be surfaced.
I find that this distinction is basically the application vs library distinction in the article. Application developers tend to "just want to bubble up a string" whereas library developers tend not to.
- woodruffw 4y agoThis is a good reason (for the purposes of stability), but IMO a misuse of `Result` in the standard library. It really ought to be something custom, closer perhaps to `ControlFlow`[1] (which is newer). But even that's not a great fit. [1]: https://doc.rust-lang.org/std/ops/enum.ControlFlow.html https://doc.rust-lang.org/std/ops/enum.ControlFlow.html