News for hackers. Stuff that matters.
Re:Announcing Rust 1.14 by echelon on Thursday December 22, 2016 @02:57PM (#13239882)
This is NOT idiomatic Rust. If you're new to Rust, please don't let this give you a taste for the language. Clean Rust code looks very elegant.
Re:Announcing Rust 1.14 by netcraft on Thursday December 22, 2016 @03:35PM (#13240157)
how would this be written idiomatically today?
Re:Announcing Rust 1.14 by echelon on Thursday December 22, 2016 @04:06PM (#13240393)
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.

Re:Announcing Rust 1.14 by lisivka on Thursday December 22, 2016 @03:56PM (#13240318)
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.
Re:Announcing Rust 1.14 by EugeneOZ on Thursday December 22, 2016 @04:52PM (#13240696)
Use "try" or "?" if possible, pattern matching otherwise.