Re:Sapper, a lightweight web framework written in Rust
by dikaiosune on Wednesday June 01, 2016 @02:12PM
(#11816780)
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):
[ Parent
| on HN ]
Re:Sapper, a lightweight web framework written in Rust
by cfallin on Wednesday June 01, 2016 @02:23PM
(#11816866)
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.
Re:Sapper, a lightweight web framework written in Rust
by yarper on Wednesday June 01, 2016 @04:24PM
(#11817825)
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
Re:Sapper, a lightweight web framework written in Rust
by kazagistar on Thursday June 02, 2016 @03:52AM
(#11820991)
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.
Re:Sapper, a lightweight web framework written in Rust
by yarper on Thursday June 02, 2016 @11:47AM
(#11823442)
agreed!
Re:Sapper, a lightweight web framework written in Rust
by dikaiosune on Wednesday June 01, 2016 @02:25PM
(#11816881)
Right, and the Rust result also produces a compile-time warning (which can be escalated to an error) if the value isn't checked.