I'm programming in rust nowadays and like Go, error handling is explicit. Rust has syntactic sugar with the "?" keyword to forward errors and let the caller handle the error. Does Go have the same feature ?
Nope, Go doesn't have that.
Both Rust and Go use the return value as an indicator of an error and enforces handling it on spot, but that is the only similarity.
Go's error interface is defined by the presence of an Error() string method and cannot do anything, but becoming a string.
error
Error() string
Rust's Result has handy methods like unwrap or expect, along with the sugar.
Result
unwrap
expect
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'm programming in rust nowadays and like Go, error handling is explicit.
Rust has syntactic sugar with the "?" keyword to forward errors and let the caller handle the error. Does Go have the same feature ?
Nope, Go doesn't have that.
Both Rust and Go use the return value as an indicator of an error and enforces handling it on spot, but that is the only similarity.
Go's
error
interface is defined by the presence of anError() string
method and cannot do anything, but becoming a string.Rust's
Result
has handy methods likeunwrap
orexpect
, along with the sugar.