Most of the time if you forget a ? somewhere then your program won't compile, because you'll have an Option/Result, not the value you're expecting in a given expression.
You're correct though that there's a hole where functions return Result<(), Error> because you can ignore the return value without getting an error, however the Rust compiler will spit out a warning for an unused Result:
warning: unused `std::result::Result` that must be used
--> src/lib.rs:9:5
|
9 | f?.read_to_string(&mut s);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_must_use)] on by default
= note: this `Result` may be an `Err` variant, which should be handled
So while I agree that Rust isn't head and shoulders better than C++ in every way, I think error handling is currently one area where Rust has a significant advantage.
Most of the time if you forget a
?
somewhere then your program won't compile, because you'll have anOption
/Result
, not the value you're expecting in a given expression.You're correct though that there's a hole where functions return
Result<(), Error>
because you can ignore the return value without getting an error, however the Rust compiler will spit out a warning for an unusedResult
:So while I agree that Rust isn't head and shoulders better than C++ in every way, I think error handling is currently one area where Rust has a significant advantage.
thanks for the info Nick.