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.
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.