3 ms·
The semantics are very different, even if the syntactic results are superficially similar. In Rust you cannot retrieve the value on success without explicitly h
by duped 5y ago
The semantics are very different, even if the syntactic results are superficially similar. In Rust you cannot retrieve the value on success without explicitly handling the error - that's forbidden by the type system. Additionally you can't have an unitialized error result, or force the callee to check the argument for null.
I think the example is pretty weak, because the difference isn't that meaningful in an isolated case. Consider something like parsing an HTTP request - it is difficult to even write the toy example without handling the major error cases. The result is a robust program by default.
- petmon 5y agoRust sometimes throws away errors when they would be awkward to handle - close() in Drop and println!() are important examples. A Hello World with a closed stdout will correctly fail in C but "succeed" in Rust because it ignores EBADF. https://github.com/rust-lang/rfcs/pull/1014 https://github.com/rust-lang/rfcs/pull/1014