Closed
Description
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
.