Wordle aid CLI - first Rust program


I was hoping to get some feedback on my first Rust program. It's a small CLI program designed to help solve wordle puzzles.

Any tips on how to improve architecture and performance would be appreciated. You can view it on GitHub here. Thank you!

A minor one: you don't need to put the string literals into a vec. You can just read them from the binary, like https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=67ff4f09d766c0eb61414f62e1c60016

You might be able to explore using b"arose" to deal in [u8; 5]s instead of &strs. I don't know if that would simplify any parts of the code.

Thank you for the tips!! Both of those are great. I implemented the first and I'll think on what I can improve by using byte slices in that form- enumerating over them should be cleaner for starters.

Note that I'm not sure whether [u8; 5] will actually be easier. Just something to experiment with.

Hmm, something else I noticed:

Some(x).unwrap() is just x, so you can simplify a bunch of that.

Stylistically, I'd suggest putting GuessedLetterResult::CorrectSpot instead of _ there. When there's only one left, might as well make that clear to the reader, rather them wonder if they remembered all the other cases.

For that you're looking for https://doc.rust-lang.org/stable/book/ch10-02-traits.html#returning-types-that-implement-traits, as something like -> impl Iterator<Item = TheItemTypeHere>.

You should probably be deriving Copy on more of your types. GuessedLetterResult and GuessedLetter are both small-and-simple, great candidates for Copy.

Awesome, that's great feedback! For some reason it didn't occur to me that Copy would be derivable as well (I was pretty liberal with skimming docs, heh..). But in hindsight it makes total sense that would work when all members implement copy.

For returning an iterator, stack overflow had similar suggestions, and I tried brute forcing a signature without really knowing what I was doing, but no luck.. I just need to spend the time to really understand traits and lifetimes to get it right.

It was very surprising to me that I couldn't just highlight the following lines and extract a function with rust-analyzer. When I tried that with the lines below, the generated function had a return type of "_", so I guess the compiler couldn't figure it out either, which made me feel less bad :slight_smile:

Again thanks so much for the review. I wasn't expecting anyone to be so thorough, that's very kind of you and I really appreciate it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.