3 ms·
I haven't done much Rust, but why isn't there a safe way to do some of this implicitly? If you don't want to think about errors and just want to crash, then I f
by nathan_f77 9y ago
I haven't done much Rust, but why isn't there a safe way to do some of this implicitly? If you don't want to think about errors and just want to crash, then I feel like there should be a sane way to crash the script with a default error message. Could you write a thin abstraction to achieve this? Maybe there could be a new crate called "rust-script" or something, where the goal is to write code as easily as Python or Ruby.
Again, I'm not a Rust developer, but it's not hard to imagine an abstraction (or even a transpiler) that makes it easy to read a file, parse it as JSON, and do something with the data.
- AsyncAwait 9y agoThere's unwrap() and panic!, does that not do what you want?
- bombless 9y agoYour answer is simply `unwrap`. OP know it but struggles to believe it, it's that simply.
- rvense 9y agoAs the other comment says, that's exactly what's done with unwrap and try. You do obviously have to write that out, but on the other hand that means you know where to add the error handling when you come back after the fact. It might take a little getting used to, but it's a decent compromise. I'd say it's a matter of taste, but yeah, there are a few more characters there.
- MichaelGG 9y agoCouldn't there be an opt-in Deref for Option and Result? Then you could just pretend everything unwrapped fine.
- leshow 9y ago> If you don't want to think about errors and just want to crash, then I feel like there should be a sane way to crash the script with a default error message. We have `expect` it's like unwrap(), but takes a string. When the program encounters some error, it will exit and print the string.