Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve documentation of RefCell::get_mut #40203

Closed
comex opened this issue Mar 2, 2017 · 2 comments
Closed

improve documentation of RefCell::get_mut #40203

comex opened this issue Mar 2, 2017 · 2 comments
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools P-medium Medium priority

Comments

@comex
Copy link
Contributor

comex commented Mar 2, 2017

From IRC:

<bletch>	how do I set the value of a RefCell? all the examples I see are about mutating it, not setting the value
<Mutabah>	You can overwrite the existing value if you can mutate
<Mutabah>	Just by doing `*cell.borrow_mut() = new_value`
<bletch>	but then it says it's an immutable borrowed content
<bletch>	when inside TLS
<bletch>	"cannot borrow immutable borrowed content as mutable"
<bletch>	with(|f| *f.get_mut() = new_gc)
[..]
<bletch>	ok, borrow_mut fixed it
<bletch>	yeah, I was using get_mut
<bletch>	I don't know why they're different

The documentation for get_mut is not terrible:

Returns a mutable reference to the underlying data.
This call borrows RefCell mutably (at compile-time) so there is no need for dynamic checks.

but I think it could be more explicit that get_mut is for special circumstances / usually not what you want. The name get_mut may tend to confuse newbies since it looks 'basic' and very similar to borrow_mut.

@steveklabnik steveklabnik added A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools P-medium Medium priority and removed A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels Mar 10, 2017
@steveklabnik
Copy link
Member

doc team triage: p-medium

@GuillaumeGomez
Copy link
Member

Took a look at it and the prototype of the method seems clear enough to me:

fn get_mut(&mut self) -> &mut T

It clearly expects self to be mutable. However, I'll add something about it to be clear but I don't think this is really necessary...

bors added a commit that referenced this issue Apr 24, 2017
Add more explanation on RefCell::get_mut

Fixes #40203.

r? @rust-lang/docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

3 participants