Feedback for first Rust Program

https://sh.itjust.works/post/57050433

@Yeahboy92 - sh.itjust.works

Lemmy

You panic a lot on errors in functions where you return a result. Almost all of these are due to input problems not programming logic errors. These really should be return from the functions as errors so higher up functions can handle them how they might need to rather than just imminently crashing the program. Really panics should only be used when the situation should never occur and if it does that indicates a bug in the program - or you are being lazy with small/test code/one off scripts (but in this case why return any errors at all, you might as well just .unwrap() on everything instead of ?.

To Panic or not to Panic Thank you for your pointer. I just remember this from the docs. So basically, the general rule is only to use panic when something bad really happened, and my program cannot continue right? otherwise always return the error?

Really panics should only be used when the situation should never occur and if it does that indicates a bug in the program

I’ll rethink the use of panic in my code

would this section suffice? doc.rust-lang.org/…/ch09-00-error-handling.html

To panic! or Not to panic! - The Rust Programming Language