Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It was bad coding.

.unwrap() is not required to be used.

use:

if let Some(value)=something_to_unwrap{

}else{ // log an error and exit!! }



Fun fact: that's what an unwrap does. It panics, which causes the error to be logged and the thread ended.


And one of the fun things about how unwrap() does that automatically, is that if you are working with an orchestrator with retry logic, you won't need to (re-re-re-re-re-)write your own for the entire program - the orchestrator will see the error, log its output, and try again in high volume workloads, or move on to the next request - this is incredible and nice to use especially when a failure in one request doesn't need to fail the entire application for all requests.

I shy away from unwrap() in almost all cases (as should anyone!) but if you are running a modular system, then unwrap when placed strategically can be incredibly useful.


I think the commenter meant "return a Result<_>" instead of exit. Your snark is perhaps amusing, but not particularly charitable.


Maybe rust should put a function in the core library which does this! Send a PR!





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: