You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<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.
The text was updated successfully, but these errors were encountered:
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
From IRC:
The documentation for
get_mut
is not terrible:but I think it could be more explicit that
get_mut
is for special circumstances / usually not what you want. The nameget_mut
may tend to confuse newbies since it looks 'basic' and very similar toborrow_mut
.The text was updated successfully, but these errors were encountered: