rustlings icon indicating copy to clipboard operation
rustlings copied to clipboard

Improve hint for as_ref_mut

Open Frosthage opened this issue 3 years ago • 2 comments

The hint for as_ref_mut was written before the function num_sq was added and is currently incorrect. I'm pretty sure you can improve this hint, but at least it's correct

Frosthage avatar Jul 26 '22 20:07 Frosthage

Just realised this existed and went to put in my own PR instead (That I've now closed) - @Frosthage Instead of straight up adding the answer there (and also limiting it to a u32, like @CaliViking mentioned above), what if it had it's own hint saying something like "Consider the type you'd want to use" - I think it's already clear (ish) from the actual comments on that file that it wants to be T: AsMut<_> like the others are something like T: AsRef<str> and the hint just needs to steer the user towards the correct data type. I'm not sure what the data type we could hint towards should be - I used u32 in my own solution, but any numeric one would be fine (does this pass with a generic usize? I've not tested that)

Ttibsi avatar Jan 17 '23 17:01 Ttibsi

FWIW, I just went through all the exercises (as a genuine newbie to Rust) and this was the only exercise I failed to complete properly (as far as I can tell), and I found the hint quite unhelpful.

I could fix it if I specialised num_sq to u32 (with or without the Box), but trying to do with with a combination of generic and Box seemed hard, especially since a lot of types don't implement multiplication. I'd love to see what a correct solution with the generic, handling the Box.

njr0 avatar Mar 03 '23 14:03 njr0

Great improvement for sure!

0xVitalii avatar May 31 '23 18:05 0xVitalii

@all-contributors please add @Frosthage for content

manyinsects avatar Jun 12 '23 10:06 manyinsects

@shadows-withal

I've put up a pull request to add @Frosthage! :tada:

allcontributors[bot] avatar Jun 12 '23 10:06 allcontributors[bot]