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

`try!(foo)` is roughly equivalent to this (invalid) code:

    foo().unwrap_or_else({ |e| return Err(e) })
Or in Go terms:

    a := try!(foo)
is equivalent to:

    a, err := foo()
    if err != nil {
        return nil, err
    }
Basically it will take the result of foo, and if foo returns an error it will return the error itself.

https://doc.rust-lang.org/beta/std/result/ has lots of examples of alternative ways you can deal with the error case, or the Ok() case of a result.



It's worth mentioning that try! is a macro that basically takes that expr and turns it to something similar to your go example.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: