Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add refcell1 exercise#1779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
exdx wants to merge1 commit intorust-lang:main
base:main
Choose a base branch
Loading
fromexdx:feat/refcell
Open

Conversation

@exdx
Copy link
Contributor

Adds a basic exercise to introduce the concept of aRefCell. This API is not necessarily for beginners but is useful to have knowledge of.

@manyinsects
Copy link
Member

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?

@exdx
Copy link
ContributorAuthor

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.

Signed-off-by: denton <denton24646@gmail.com>
@exdx
Copy link
ContributorAuthor

exdx commentedDec 2, 2023

@shadows-withal I have updated the example to use thecompile instead oftest 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.

@mo8it
Copy link
Contributor

The exercise teaches the usage ofRefCell very well, but not reallywhen to use it. It might be just confusing why the user shouldn't use&mut self since aRefCell is not really required in this example at all.

@exdx
Copy link
ContributorAuthor

The exercise teaches the usage ofRefCell very well, but not reallywhen to use it. It might be just confusing why the user shouldn't use&mut self since aRefCell is 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.

@mo8it
Copy link
Contributor

I am a very new maintainer. Let's wait for the feedback from @shadows-withal first :D

@Piyuuussshhh
Copy link

Piyuuussshhh commentedOct 4, 2024
edited
Loading

I think exercises on Cell, RefCell, RwLock and Mutex in sequence would be nice. I remember there was a video that explained when these smart pointers become useful quite nicely. It explains why and when interior mutability is required.
The dude took the construction of a graph and updating the value of a node & its neighbors as the running example throughout the vid. If you want, I could link it!

PS: I'm sorry if exercises on these features have already been discussed and decided. I just finished all exercises and was wondering why these weren't included. BTW doing god's work, you guys! Thank you so much for creating this project!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@exdx@manyinsects@mo8it@Piyuuussshhh

[8]ページ先頭

©2009-2025 Movatter.jp