DEV Community

Discussion on: Go and Rust error handling

Collapse
 
chayimfriedman2 profile image
Chayim Friedman

.expect() (or .unwrap()) are not error handling mechanisms, and certainly not equivalent to if err != nil in Go. The usual error handling mechanism in Rust is the ? operators, that has the same meaning as if err == nil { return; }.

Collapse
 
buymymojo profile image
BuyMyMojo

Would that be done like this?:

if let Err(Reason) = somefunc() {
 // handle error?
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
chayimfriedman2 profile image
Chayim Friedman

Or match.