this post was submitted on 21 Apr 2024
0 points (NaN% liked)
Rust
7651 readers
10 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
I took a very quick look at the code and one thing I noticed, is that you're using
&String.For a parameter in a function, you always want to use
&strinstead, as explained here: https://doc.rust-lang.org/book/ch04-03-slices.html#string-slices-as-parametersI believe, it's also not a thing to return
&String(nor to store it in a struct). I don't have as solid of an explanation for it, it's just not something I see much in Rust code (and in the chapter above, they do use a&stras return value, too).Maybe someone else can weigh in on that.
The same applies for:
&[]rather than&Vec&Pathrather than&PathBuf&OsStrrather than&OsStringI would also recommend using Clippy. I think, you can just run
cargo clippyand it'll work.It's a linter and will tell you lots of code style issues (like using
&Stringas a parameter).If you've never run it, it might spit out a lot of warnings at first, but working through them can teach you quite some things.
Thanks, that was a lot of info I didn't know either. I was wondering how to use clippy...