logoalt Hacker News

vorticalboxtoday at 8:54 AM2 repliesview on HN

I don't fully get the argument about errors.

in rust say a function returns Result<T, E> so either the we get a result all an error how is that different from (int, err) in go?

do you not still need to handle the error?

in go you just return the error up to whatever the top caller is.


Replies

moltoneltoday at 9:49 AM

Go funcs can return both a value and an error, or neither, it's a common gotcha. Having to check the behavior each time is no fun.

Missing error handling is checked at compile-time in Rust (lint-time in Go), and can be enabled for any struct or function (https://doc.rust-lang.org/reference/attributes/diagnostics.h...), not just `Result<T,E>`.

Returning an error to the caller in Rust can be done with a single character.

ssfaktoday at 9:06 AM

In Go you can ignore the error value though, and use directly the returned value (`int` in your example). In Rust you cannot do that, you need to unwrap the Result or use the `?`

show 1 reply