this post was submitted on 19 Mar 2026
17 points (90.5% liked)
Rust
7865 readers
36 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Welcome to Rust, I hope you enjoyed learning and using it :)
One major advice would be to run
cargo clippy, which gives a lot of helpful hints. Apart from that I also have some feedback.These comments should be doc-comments (
///) so thatcargo docpicks them up.Not saying that your return type is bad, but in general you might be interested in crates
thiserrorandanyhowthat simplify error handling.Duration::from_mins(1)would be much more readable.You should almost never panic. Your function already returns a Result<>, so you should be using that for error handling.
Not Rust specific, but usually I recommend to handle errors first, and return from the function early. This way you reduce cognitive load on the reader, and reduce nesting of if-blocks.
There's a convenient method to split in two substrings that you could have used:
I would probably write a regular expression that replaces all contiguous whitespace with a single space instead.
Aren't you trimming this new line off in line 181?
This is somewhat inefficient, since you'll be allocating and copying your string here.
Hello and Thank You :D Rust really intrigues me so i really want to explore more about Rust
Thank you for your input. I'll refactor my code
Conceptually, error handling in Rust is incredibly simple: if a function can fail, its return type is an enum of either the result of the function (in case of success) or a description of the error that happened. This enum is called Result. See:
You don't. You can 100% handle errors without any additional dependencies, and probably you should be doing that in the beginning. The crates simply add a little bit of syntactic sugar to simplify some boilerplate that you'll have to start writing as soon as your error handling gets sufficiently complex.
I see, maybe i'm still not familiar with it. I'll explore more about error handling in rust later.
Thank you for the pointer.
For the crates, basically its a wrapper i presume? To remove the boiler plate right?