4 ms·
how would this be written idiomatically today?
by netcraft 10y ago
how would this be written idiomatically today?
- lisivka 10y agoWith proper error handling instead of unwrap(), which means "I don't care about errors here".
- Dylan16807 10y agoWhat does proper error handling look like when I want to use the same "invalid node" error for most of those unwrap calls?
- EugeneOZ 10y agoUse "try" or "?" if possible, pattern matching otherwise.
- staticassertion 10y agoYou can use map or and_then, you can write a macro, you can use try!, you can use if let, etc. There are lots of ways to handle errors in rust.
- echelon 10y agoThere are so many nice options here. For the cleanest code, I would use `?` and a `From` impl for the error transformation. If I didn't want to use `From`, I'd use `map_err`, `and_then`, etc. Both the Result and Option types have wonderful interfaces for chaining.