3 ms·
My Rust on `try!` is rusty... no pun intended, iirc it is the equivalent of: if err := someFn(); err != nil { return err } Where as `unwrap()` is: if err
by fizzbatter 10y ago
My Rust on `try!` is rusty... no pun intended, iirc it is the equivalent of:
if err := someFn(); err != nil { return err }
Where as `unwrap()` is:
if err := someFn(); err != nil { panic(err) }
So a little dif than your example, fwiw. (Not agreeing or disagreeing with any of the statements, merely commenting on your question)
- justinsaccount 10y agounwrap is also kind of neat in that it 'unwraps' the value, so something that converts strings to ints intval = convert("42").unwrap() is like if intval, err := convert("42"); err != nil { panic(err) } but you can not do intval = convert("42") and pretend it can't fail, but in go you can do intval, _ := convert("42") the rust unwrap would most similar to a intval := mustConvert("42") in go, but 'must' type functions don't exist for every method in every library.