4 ms·
Isn't Rust's result type basically the same as Abseil's Status, or am I missing something ? https://abseil.io/docs/cpp/guides/status https://abseil.io/docs/cpp/
by antoinealb 3y ago
Isn't Rust's result type basically the same as Abseil's Status, or am I missing something ? https://abseil.io/docs/cpp/guides/status https://abseil.io/docs/cpp/guides/status
- steveklabnik 3y agoGenerally the same idea, yes. Your parent mentioned a key difference though: "and pattern matching." enums in Rust have much stronger language support. But there are also differences, for example, errors must be absl::StatusCode, whereas enums in Rust allow for arbitrary error payloads. Also don't discount ecosystem usage: everyone uses Result in Rust, abeseil isn't used by most things, and std::expected has its own issues (though I can appreciate how tough making those calls is) and only landed in C++23, so it's not as widely used as Result either.
- adastra22 3y agoSibling comment mentioned pattern matching, but didn’t point out the important point that the rustc compiler makes sure all patterns matches are exhaustive. To use a C example, if you add a new definition/variant to an enum, suddenly all switch statements over that enum will fail to compile (unless there is a default: branch). This does eliminate a large swatch of logic errors, though by no means all.