|
|
|
|
|
by cyphar
1949 days ago
|
|
> to this day I can't wrap my head around the need to unwrap almost every single variable/function/whatever. Think of Result as (foo, err) bundled into one thing. result.unwrap() is then equivalent to: if err != nil {
panic(err)
}
And the ? operator is: if err != nil {
return ..., err
}
You don't need to unwrap (or ?) everything, just things that return a Result -- which is the same as functions which return an error in Go. The advantage of Result is that you can never forget to handle the error because the compiler requires you to get the value out of the Result in such a way that you have to handle errors.Don't get me wrong, there are complicated things in Rust, I just don't see how Result-based error handling is one of them. This is also not a new idea, many languages have something similar. |
|