Hacker News new | ask | show | jobs
by cfallin 3675 days 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.
2 comments

It 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

That 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.
agreed!
Right, and the Rust result also produces a compile-time warning (which can be escalated to an error) if the value isn't checked.