rustlings
rustlings copied to clipboard
enums3 feedback
You can "cheese" enums3 by putting the test's desired values in the match statements:
match message {
Message::Resize { width, height } => self.resize(10, 30),
Message::ChangeColor(red, green, blue) => self.change_color(255, 0, 255),
Message::Quit => self.quit(),
Message::Move(Point) => self.move_position(Point),
Message::Echo(String) => self.echo(String),
}
This passes the test, albeit with a bunch of warnings about how the variables are unused.
Maybe add a second pass test to make sure the values are being passed through from state.process()?
I also found that I had absolutely no idea why I would be using "r, g, b" over "red, green, blue" when these are not technically defined by me. Is this some function of structs/enums? Is it part of a standard library? Is it specific to rgb?
Also, maybe this exercise should take further advantage of match patterns? If the exercise's purpose is to teach match pattern syntax, I think maybe it should show off exhaustive match patterns as well. (Or maybe there should just be an entire exercise folder dedicated to match patterns, because this throws several new concepts at you at once.)
Hopefully I am not wasting time with this issue, I just found this exercise really confusing.
Rustlings avoids trying to prevent users from cheesing exercises. It is not a test, it is something people use to learn on their own. We try to prevent passing by mistake, but not cheesing on purpose.
I also found that I had absolutely no idea why I would be using "r, g, b" over "red, green, blue" when these are not technically defined by me. Is this some function of structs/enums? Is it part of a standard library? Is it specific to rgb?
I improved the choice of variable names in the solution in https://github.com/rust-lang/rustlings/commit/f516da4138111aa6eff0970471b8a37182c09fad. But I am not sure that I correctly understood what you mean here. Could you please elaborate?
Also, maybe this exercise should take further advantage of match patterns?
Teaching about nested pattern matching in a new exercise is a good idea. Could you please open a new issue for this? :)
We try to prevent passing by mistake, but not cheesing on purpose.
i actually didn't cheese it on purpose, it was a mistake and i only found out because i checked the solution myself afterwards, i thought i just needed to make it match what the tests wanted. may be a quirk with how i learn (or avoid learning at all) myself
I improved the choice of variable names in the solution in f516da4. But I am not sure that I correctly understood what you mean here. Could you please elaborate?
-> typing this after looking back over the original code just now: i think i was just having a """"little bit"""" of trouble with reading the rustbook. didn't understand how it was accepting r, g, b when they weren't used earlier in the code and i can easily see now that it was using those as u8, u8, u8.
i actually didn't cheese it on purpose, it was a mistake
Then we should improve the tests. You are welcome to open a PR :D