Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's an empty tuple stuffed into an enum variant called Ok. The empty tuple plays the role of the traditional void.


Importantly, it's the Ok variant of the Result<(), SomeError> type, which is richer than a boolean because it carries information about why/where an operation failed, not just whether it succeeded or failed. It's similar to (but not identical to):

    public void someOperation() throws SomeException { ... }


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.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: