There's a crate for that™: https://crates.io/crates/yolo
Re:Announcing Rust 1.14
by openasocket on Thursday December 22, 2016 @03:21PM
(#13240048)
There is: make a trait called SimplerUnwrap<T> or something with the method u(self) -> T. Implement it for Option<T> and you are good to go!
Why not use C instead? I see no benefit to use complicated language which cares about errors and then completely ignore that care.
Re:Announcing Rust 1.14
by openasocket on Thursday December 22, 2016 @05:06PM
(#13240796)
You're not ignoring errors with unwrap(): if there is an error, the program will print out a stack trace and exit. If you have some operation that could potentially fail but you know it won't (like if you are sure that node has a parent) what do you do? If the operation actually does return an error, it means what you thought to be true was wrong, and in some cases that means something has gone seriously wrong, and your program should immediately stop so you can debug it. You can try to handle the error yourself, using try! or the ? operator, but unless you plan to be able to recover from that error, or you want to output a more end-user-friendly error message than a stack trace, what's the point?
Is there a way to rename / alias methods like that?
edit: I see ? is going to be a trait you can implement to do that, so that'll be nice (probably).