#Suggestion and feedback for my first script in Rust
14 messages · Page 1 of 1 (latest)
apart from that, your code is actually not too bad for a first script 🙂
of course, it could be cleaner, so don't hesitate to rewrite it when you have a bit more experience in Rust
I don't think input should need an underscore, as it's both used in the function, and returned as it's last statement, so that shouldn't produce any warnings...
Similarly in the case of the convert function, the return isn't nessacary, due to being the last statement in the function, it would return the value from the match statement implicitly...
Are you familiar with clippy? 😇
Your convert returns 0 on bad input, which isn't good, as it hides the error in a sentinel value
Your function should return a Result or an Option instead, and you can then handle that in the caller and print an error if it's invalid
Or alternately (I prefer this) you can make an enum for Celsius and Fahrenheit, making the concert function infallible. You'd match on the char outside and turn it into the enum, displaying an error if it's invalid
ah fine, the book should tell you more about it later 