Hey guys! This is my first time using the rust language, after hearing about it a lot. I've never really used a statically typed language that yells at you this insanely loudly for even the smallest error regarding mutability and/or memory management.
So long story short, after looking up the basics and many reading the docs sessions later, I got myself a simple guess the number game that I'd like for you all to review, and tell me where I could improve it or just quick tips and tricks and the like.
let usr_num = usr_num.trim().parse::<u8>().expect("Failed to parse");
Since this is user input you shouldn't expect it to be a valid number. It could be typed wrong, it could be larger than 255 or negative.
But using .expect() your program will appear to crash (panic). Instead match on the result to get a valid number or loop again after prompting the user that their input wasn't valid.
Your first expect is fine because it is reasonable to expect the terminal io to function correctly, even if it isn't guaranteed.
Yeah, that seems a lot more reasonable to do so! It'd probably be really frustrating to mistype a letter, just before getting the number, and instead of simply asking again, it "crashes". Thanks a lot for that insight!