Re:Announcing Rust 1.14
by netcraft on Thursday December 22, 2016 @03:35PM
(#13240157)
how would this be written idiomatically today?
[ Parent
| on HN ]
There 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.
With proper error handling instead of unwrap(), which means "I don't care about errors here".
Re:Announcing Rust 1.14
by Dylan16807 on Thursday December 22, 2016 @04:16PM
(#13240461)
What does proper error handling look like when I want to use the same "invalid node" error for most of those unwrap calls?
Re:Announcing Rust 1.14
by staticassertion on Thursday December 22, 2016 @07:28PM
(#13241782)
You 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.