3 ms·
You can always use “unwrap()” in throwaway code. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4b7b5949197445ab3c95ef09bd9251d3 https
by ay 4y ago
You can always use “unwrap()” in throwaway code.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4b7b5949197445ab3c95ef09bd9251d3 https://play.rust-lang.org/?version=stable&mode=debug&editio...
If that code ever gets more use than that you expect, you can trivially find all the uses of “unwrap()”, and add the proper error handling. And yes there are quite a few places where things can go wrong.
But this explicit “signing for technical debt” when it relates to error handling is a really convenient productivity feature in practice.
A simple throwaway CLI for your own use is absolutely fine to use unwrap(), and you can fix it later on if it becomes a problem.
- xyzzy4747 4y agoUnwrap is good to use for things that are expected to work 100% of the time. If unwrap fails in such situations, it’s fine to have the program panic and shut down.