Three links to three github repos are not particularly a self contained example of anything…
Anyhow, I rewrote untrusted and ring to use ?, and it took 10 minutes to do so (for both). The only error handling that happens is of the form:
let a = some_fn()?;
if some_cnd {
a
} else {
Err(b)
}
or
let a = some_fn()?;
let b = some_other_fn()?;
if some_cnd {
(a, b)
} else {
Err(c)
}
But basically the following describes the error handling of those projects:
- there is very little error handling code (almost zero compared to non-error handling code),
- there is no chaining of errors (none at all),
- there are no fluent/functional APIs being used. Instead the pattern: “try something, perform some side-effecting operation on something result, check side effects, return based on side effects” is used a lot (probably for performance).
Whether ? reads better than try! in these cases is obviously subjective, but arguably, for the little amount of error handling code that there is, if you really want to be explicit, you don’t even need to use try!. And if you are willing to use try!, replacing it with ? doesn’t make things worse (it might just require one getting used to it, but if you want to keep using try! I think that is fine too). The only change is:
let a = try!(foo(b));
becomes
let a = foo(b)?;
But that’s basically it, these projects don’t do any “more complicated” error handling.
This is why I think that in the particular field / style that these crates are written, whether ? or try! or try ... catch is accepted is kind of irrelevant, since the crates do so little error handling that whatever solution is stabilized, they will be barely affected by it (if at all).
It is worth remembering that Rust is used in many different fields. Some of them do no error handling at all, and some of them do a lot of error handling, chaining errors all the time. If you work in a field where almost no error handling is required, and when it is required, a simple try!(foo(a)) suffices, then obviously you won’t see any benefit in adding ?.
This doesn’t mean that ? doesn’t add any value to Rust, but rather that it doesn’t add any value to the particular field in which you are using Rust. Systems programming languages are used in so many fields that it is impossible to know what the majority of programmers are actually doing. One of Bjarne’s famous quotes is that nobody knows what most C++ programmers do. The same can be said about Rust.