r/learnrust • • 11d ago

New to rust, how's my progress so far?

Hello, as you might have read from the title, i am new to rust, and being new to rust also means looking for ways to further improve, and one way to do that is to receive feedback, which i am seeking from this subreddit. I've read parts of the rust book and created projects in rust to put my skills to the test. I am currently working on a simple file IO CLI tool (https://github.com/reehanthenew/Simple-file-IO-CLI-tool/tree/main) and im currently proud of my progress. If i could receive some feedback (i accept any forms of feedback) that would be most appreciated. If i could receive more beginner-friendly projects or more learning materials, that would be much more appreciated. If you would like to monitor my growth, feel free to here: https://github.com/reehanthenew?tab=repositories

7 Upvotes

4 comments sorted by

3

u/fbochicchio 11d ago

The first two funcions, prompt and pathname, do exactly the same thing, albeit for different purpose. I would suggest to only use one, maybe renaming it in a more neutral way. Also, I would make a general purpose function that both prints the question and get the answer.

Also, when getting the choice about what to do , you make multiple conversions to integer of the same string and don't check if the user answer with something different from a number.

These are not rust issues, but general programming issues, btw.

More specific about Rust : are you aware that expects crashesthe program if the underlying function returns an error? Sure, you get a nice error message but then the program quits. Is this the behaviour you want? If not, learn about error handling in Rust.

HTH

1

u/OkBug7820 11d ago

still trying to get the hang of error handling, thanks for your comment on expect i will be changing that line. As for pathname i was initially confused about how functions were called at first coming from a python background, i was not expecting it could be called with the variable as soon as it was made considering in python we make the variable and then call that variable to call a function. (That is, if we put functions inside variables.) I learned my mistake but forgot to modify the rest of the code. As for getting the choice about what to do, i don't understand what you mean by "you make multiple conversions to integer of the same string", and i didnt want to bother checking if the user answers something different other than a number because it's a very rare scenario that users lack the ability to write 1 or 2 and instead write one or two but i should probably implement that either way. Would using the OR operator be a good fix for that?

1

u/_player620 9d ago

Not rust, but git related: don't commit binaries unless absolutely necessary. They tend to bloat git object index. Use .gitignore config file to exclude build artifacts: https://github.com/rust-lang/rust/blob/main/.gitignore Try to utilize separate build directories, so binaries don't mix with sources.

1

u/OkBug7820 9d ago

alright thanks!