DEV Community

Killing unwrap()

Dimitri Merejkowsky on January 30, 2019

Originally published on my blog. Wait, what? Who do you want to kill? In Rust, to indicate errors or absence of a value we use types na...
Collapse
 
jeikabu profile image
jeikabu • Edited

I'm definitely guilty of excessive unwrap()-ing. It's just so easy to do and it feels like an assert().
And good job pointing out the combinators on Result and Option. Just this weekend I realized I had re-invented map() (poorly) and went back and re-factored some code.
One thing I found really helpful is main and tests being able to -> Result<>. Makes it a lot easier to move "correct" code using ? between tests/lib/bin.

Collapse
 
dmerejkowsky profile image
Dimitri Merejkowsky

Did not know about tests being able to return Result<>, thanks for pointing that out.

I'll update the article