3 ms·
I like to compare it to the "comma error" idiom in Go, i.e., `result, err = doStuff(...)`. The Rust prelude's Result enum is a less ad-hoc version of that.
by cfallin 10y ago
I like to compare it to the "comma error" idiom in Go, i.e., `result, err = doStuff(...)`. The Rust prelude's Result enum is a less ad-hoc version of that.
- dikaiosune 10y agoRight, and the Rust result also produces a compile-time warning (which can be escalated to an error) if the value isn't checked.
- yarper 10y agoIt supports that kind of error handling too, fn something() -> (String, String) ... let (result, err) = something() It's just that Result is preferable because you can pattern match on it
- kazagistar 10y agoThat would be fn something() -> (Option<String>, Option<String>) Because the Rust types aren't nullable by default. But that more clearly demonstrates that Result types are better since they enforce that the error and result are mutually exclusive.
- yarper 10y agoagreed!