book icon indicating copy to clipboard operation
book copied to clipboard

Potential improvement in RefCell<T> and Rc<T> sentences

Open petern48 opened this issue 10 months ago • 1 comments

In the last paragraph of the Allowing Multiple Owners of Mutable Data with Rc<T> and RefCell<T> section, we have the following.

This technique is pretty neat! By using RefCell<T>, we have an outwardly immutable List value. But we can use the methods on RefCell<T> that provide access to its interior mutability so we can modify our data when we need to.

I find it odd that the book concludes this section by only discussing the role of RefCell<T> and not the Rc<T> part. To me, this would sound more natural as "By using Rc<T>", ... But we can also use the methods on RefCell<T> ... Was the first RefCell<T> meant to say Rc<T> instead? If not, I still feel like this part can be improved.

I'm happy to submit a PR if there's a need.

petern48 avatar Jun 30 '25 06:06 petern48

Yes, I can remember -- this is one of the sentences from the official books, that I had to read twice. I think it is correct -- what it says is, that RefCell<T> appears to be an immutable reference, but that type provides methods that still allow modifying the actual content. At least that was my interpretation after reading for the second time.

StefanSalewski avatar Jun 30 '25 11:06 StefanSalewski