rustlings icon indicating copy to clipboard operation
rustlings copied to clipboard

enums3.rs Comment confusing for new users.

Open Acivo opened this issue 2 years ago • 2 comments
trafficstars

The comment in the enums3.rs exercise:

// TODO: create a match expression to process the different message
// variants
// Remember: When passing a tuple as a function argument, you'll need
// extra parentheses: fn function((t, u, p, l, e))

Was very confusing to me, when I was doing the exercise. It made me second guess my attempt (which turned out to be correct), because it made me think that I needed to have extra parentheses in this line:

Message::ChangeColor((r, g, b)) => self.color = (r, g, b),

After asking in Discord, I now understand that it was intended to remind me of the need for extra parentheses in a function signature, for future reference, but as it wasn't actually applicable at all in the exercise, I found myself searching for a place that I needed to place those extra parentheses.

Acivo avatar Oct 06 '23 10:10 Acivo

For reference: I believe this was first discussed here: https://github.com/rust-lang/rustlings/commit/4b6540c71adabad647de8a09e57295e7c7c7d794 And then later introduced in the pull request here: https://github.com/rust-lang/rustlings/pull/1310/

I'm still not sure why the comment was added, but if the point is to demonstrate the occasional need for double parentheses, maybe an enums4.rs would be a better solution.

CheaterCodes avatar Oct 06 '23 10:10 CheaterCodes

After having re-read, it appears that enums3.rs expects you to create a message like this, but that change was then later reversed or never applied:

enum Message {
  ChangeColor((u8, u8, u8)),
  ...
}

However, it is never indicated in the usage that this is the desired use. Maybe something like this should be added to the use case:

let color = (255, 0, 255);
state.process(Message::ChangeColor(color));

Putting the variable on a separate line makes it clear that the double parentheses added in the above commit are intentional.

CheaterCodes avatar Oct 06 '23 11:10 CheaterCodes

Fixed in https://github.com/rust-lang/rustlings/commit/708cfef3f76071d71d42053453e6b9a5b858b991 by avoiding this confusion with double parentheses.

mo8it avatar Jul 07 '24 13:07 mo8it