feat: add refcell1 exercise
Adds a basic exercise to introduce the concept of a RefCell. This API is not necessarily for beginners but is useful to have knowledge of.
I like the idea of teaching about RefCells, but I feel like this exercise would have to be somewhat more sophisticated... I'd like people to be able to see the difference of behaviour between the normal compile-time borrow check and what RefCell provides, maybe a more engaging exercise format could be converting something that's impossible with normal borrowing rules to using RefCell?
Thanks for taking a look @shadows-withal. I agree the example could be more sophisticated and I will look into updating it. Potentially following the Rust Book more closely is a good direction to take.
@shadows-withal I have updated the example to use the compile instead of test mode. I think this make the logic considerably simpler. The example is a straightforward example of using a RefCell to mutate via an immutable reference.
I think since this may be the first introduction to RefCell a user has, it's simplicity is a feature. Happy to adjust as necessary.
The exercise teaches the usage of RefCell very well, but not really when to use it. It might be just confusing why the user shouldn't use &mut self since a RefCell is not really required in this example at all.
The exercise teaches the usage of
RefCellvery well, but not really when to use it. It might be just confusing why the user shouldn't use&mut selfsince aRefCellis not really required in this example at all.
I see -- that's fair. At the risk of making the example more convoluted I can update the example to provide a scenario where refcell is a necessity.
I am a very new maintainer. Let's wait for the feedback from @shadows-withal first :D